#P7614. [2018年杭电多校]GuGuFishtion

[2018年杭电多校]GuGuFishtion

GuGuFishtion

Problem Description

Input

Input contains an integer TT indicating the number of cases, followed by TT lines. Each line contains three integers mm,nn,pp as described above. 1T31\le T\le 3 1m,n1,000,0001\le m,n\le 1,000,000 max(m,n)<p1,000,000,007\max(m,n)<p\le 1,000,000,007 And given pp is a prime.

Output

Please output exactly TT lines and each line contains only one integer representing the answer.

Sample Input

1

5 7 23

Sample Output

2

Source

2018 Multi-University Training Contest 7