#nt803. 指数方程1
指数方程1
Exponential Equation 1
Problem Description
Answer queries. Each query gives three numbers ; output the smallest non-negative integer satisfying .
Input Format
The first line contains an integer . The next lines each contain three integers .
Output Format
One integer: the smallest non-negative solution; if no solution exists, output -1.
Sample Input
4
3 7 10
688720331 114514 998244353
5 114514 998244353
688720331 407057022 998244353
Sample Output
3
-1
271880075
123
Constraints
For all data, , are guaranteed, and is coprime to .