Root

Time Limit: 15000ms
Memory Limit: 262144KB
This problem will be judged on HDU. Original ID: 5377
64-bit integer IO format: %I64d      Java class name: Main

Description

Given a number $sum(1\leq sum \leq 100000000)$,we have $m$ queries which contains a pair ($x_i,y_i$) and would like to know the smallest nonnegative integer $k_{i}$ satisfying $x_i^{k_{i}}=y_i\ mod\ p$ when the prime number $p\ (sum\ mod\ p = 0)$(ps:$0^0=1$)

Input

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

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

The next $m$ lines will contains two intgeers $x_i,y_i(0\leq x_i,y_i\leq1000000000)$

Output

For each test case,output "Case #$X$:" and $m$ lines.($X$ is the case number)

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

Sample Input

1
175 2
2 1
2 3

Sample Output

Case #1:
0
3

Source

Language: 
Theme: 
Share Code? 

Powered by NB231 | Current Style: .