- Time limit: 1.00 s
- Memory limit: 512 MB
Your task is to efficiently calculate values modulo .
Note that in this task we assume that .
Input
The first input line has an integer : the number of calculations.
After this, there are lines, each containing three integers , and .
Output
Print each value modulo .
Constraints
Example
Input:
3 3 7 1 15 2 2 3 4 5
Output:
2187 50625 763327764