Don't leave for tomorrow what you can do today, leave it for the day after tomorrow
Task
Alice Elice challenged Bob Glob to a game. Alice Elice has two piles with and gifts. Before the game starts, Alice rolls a die with faces and notes the resulting number as . The game consists of the following stages:
At the beginning, if is even, she opens all the gifts from the first pile, and if is odd, she opens all the gifts from the second pile. In the subsequent turns, they alternately pick gifts, starting with Bob. The player must open between and gifts from the remaining pile. The player who cannot open at least one gift loses.
Task
Alice wants to have many gifts next year, so she wants to find out the probability of winning the game, assuming that both play optimally.
Input data
The first line contains , the number of tests. On the next lines, , , and are given.
Output data
For each of the tests, print the chance of winning modulo (see below).
Constraints and clarifications
- Assume there exists a model of a die with faces.
- If we express the probability that Alice will win as the fraction , then you will output , where is the modular inverse of , modulo .
- Both play optimally.
# | Score | Constraints |
---|---|---|
1 | 10 | , |
2 | 30 | , |
3 | 60 | No additional constraints |
Example
stdin
3
3 2 3
333625 453145 800
1 1 1
stdout
0
855000006
0
Explanation
If the die shows the value :
- The remaining pile is with gifts Alice loses;
If the die shows the value :
- The remaining pile is with gifts Alice loses;
If the die shows the value :
- The remaining pile is with gifts Alice loses.