#Lutece1188. Log

Log

Migrated from Lutece 1188 Log

All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.

Description

Given a number sum(1sum100000000)sum(1\leq sum \leq 100000000),we have mm queries which contains a pair (xi,yix_i,y_i) and would like to know the smallest nonnegative integer kik_{i} satisfying xiki=yi mod px_i^{k_{i}}=y_i\ mod\ p when the prime number p (sum mod p=0)p\ (sum\ mod\ p = 0)

Input

The first line contains a number T, indicating the number of test cases.

For each case, each case contains two integers sum,m(1sum100000000,1m100000)sum,m(1\leq sum\leq 100000000,1\leq m\leq 100000) in the first line.

The next mm lines will contains two intgeers xi,yi(0xi,yi1000000000)x_i,y_i(0\leq x_i,y_i\leq1000000000)

Output

For each test case,output "Case #XX:" and mm lines.(XX is the case number)

Each line cotain a integer which is the smallest integer for (xi,yix_i,y_i) ,if we can't find such a integer just output "-1" without quote.

Samples

1
175 2
2 1
2 3
Case #1:
0
3

Note

175 =527175\ =5^2*7

20 mod 5 = 12^0\ mod\ 5\ =\ 1

23 mod 7 = 12^3\ mod\ 7\ =\ 1

So the answer to (2,1) is 0

Resources

Prepare for 2015 MU2015 Multi-University Training