A Number Theoretical Problem
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Given a positive integer y and a prime p, you are asked to find an integer x such that . If such x exists, output any x mod p. Otherwise, output -1.

Hint: For any integer a and positive integer b, a mod b is the remainder of a dividing b. Remind that a mod b is non-negative!

输入描述:

The first line of input contains a positive integer T, which is the number of test cases. 
For each test case, there will be one line containing 2 positive integers y, p. , p is guaranteed to be a prime)

输出描述:

Output one integer for each test case. If such x exists, output any x mod p. Otherwise, output -1.
示例1

输入

复制
3
1 97
2 97
3 97

输出

复制
1
49
65