Three integers , and are given. Compute the value of the following expression:
The first line contains the number of test cases . Each of the following lines contains three integers x~(1 \le x \le 10^9), m~(1 \le m \le 10^{12}) and p~(1 \le p \le 10^9). It is guaranteed that is a prime number.
For each test case, print the answer on a separate line.
Example 1