#d11201. GCD

GCD

GCD

Problem Description

Given integers aa and mm, count the number of integers xx satisfying 0≤x<m0 \le x < m and gcd⁡(a,m)=gcd⁡(a+x,m)\gcd(a, m) = \gcd(a + x, m).

Input Format

The first line contains an integer TT.

The next TT lines each contain two integers a,ma, m.

Output Format

Output TT lines, each containing a single integer: the answer.

Sample Input

3
4 9
5 10
42 9999999967

Sample Output

6
1
9999999966

Constraints

1≤T≤501 \le T \le 50, 1≤a<m≤10101 \le a < m \le 10^{10}.