Blitz Division

Time limit: 0.2s Memory limit: 128MB Input: Output:

Task

Alex is passionate about diverse mathematical challenges, and as a gift for you to start the new IIOT season, he gives you three positive integers AA, BB and KK. He tells you that you must use exactly KK increments (i.e., increasing a value by one) on AA and BB, in any way you want. Now, he wants to find the greatest possible value of the greatest common divisor of the two integers obtained after the increments.

For example, if A=7A = 7, B=11B = 11 and K=3K = 3, the answer is 77, because we can use all 33 increments on BB to make it equal to 1414 and gcd(7,14)=7\gcd(7, 14) = 7. However, if A=18A = 18, B=9B = 9 and K=3K = 3, the answer is 1010 (A=20A = 20, B=10B = 10 after incrementing the values 33 times).

Alex decided to test you on TT such triplets. Show Alex that math is your friend as well!

Input data

The first line contains TT, the number of test cases. Each of the next TT lines contains three positive integers, AA, BB, and KK.

Output data

You need to write TT lines, each line containing the answer for the corresponding triple of values.

Constraints and clarifications

  • 1T1001 \leq T \leq 100
  • 1A,B,K1091 \leq A, B, K \leq 10^{9}
# Points Constraints
1 0 Examples
2 30 A,B,K10 000A, B, K \leq 10 \ 000
3 70 No additional constraints

Example

stdin

4
7 11 3
18 9 3
58 38 14
68 94 231

stdout

7
10
22
131

Explanation

The first two triples of the sample case were explained in the statement. For the third triple, you can increment the numbers to 6666 and 4444, respectively. For the last triple, you can increment the numbers to 131131 and 262262, respectively. It can be proved that these values are optimal.

Log in or sign up to be able to send submissions!