RSA Attack#1561

RSA Attack

1 second
128 megabytes
Very easy

The RSA problem is as follows: given a positive integer that is a product of two distinct odd primes and , a positive integer such that \gcd(e, (p - 1) \cdot (q - 1)) = 1, and an integer , find an integer such that m^e \equiv c \pmod{n}.

Input

The first line contains the number of test cases (k \leq 2000). Each of the following lines contains a separate test case, with three positive integers , , and (e, n, c \leq 32000; n = p \cdot q; , are distinct odd primes; \gcd(e, (p - 1) \cdot (q - 1)) = 1; e < (p - 1) \cdot (q - 1)).

Output

For each test case, print in a separate line the integer .

Examples

Example 1

Loading
Loading