NINJA3 - STUNNING GCD

You are given three numbers N, a, b. You can build a number X by repeating N 'a' times and the number Y by repeating N 'b' times. Now that you have the numbers X and Y, determine the GCD of the two numbers X and Y.

Input

The first line contains an integer T, the number of test cases.

Then for each test case, there are three integers in each line: N, a, b.

Output

Print the required answer for each test case in a single line.

Constraints

1 ≤ T ≤ 100

1 ≤ N, a, b ≤ 1018

Sample

Input:
1
123 2 3

Output:
123

Added by:mombassa
Date:2016-02-17
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64 GOSU JS-MONKEY

hide comments
2016-03-02 04:10:56
comments were helpful
2016-03-01 21:32:30
A simple relation ,try few custom test case
2016-02-26 12:39:24 ATUL KUMAR SINGH
simple but after 9 wa of common mistake ac

Last edit: 2016-02-26 12:39:43
2016-02-25 20:36:41
why i am getting WA ?
test case plss..
2016-02-25 18:45:04 [Lakshman]
@dwij28 You are correct BUT do you know how much time it will take for such an massive number, this is not only the case there are many more for all n>10^9 and n <=10^18 and if a and b are (n, 2*n) .
2016-02-25 07:50:32
@[Lakshman]: Sir, I think there can be solution to the testcase you mentioned. The problem that I see in your test case is that arrays won't be sufficient to handle the answer. But the answer can be obtained without even using arrays using loops and print statement. :)
2016-02-23 08:36:42 [Lakshman]
I have doubt what will be the output if input is 123 1000000000 1000000000000000000?

EDIT:: Every solution will fail if you consider the above input.

Last edit: 2016-02-23 09:39:10
2016-02-23 07:45:13
N 'a' times mean concatenates N 'a' times
2016-02-22 21:34:18 Shivam Garg
does repeating N 'a' times mean X=N*a , or concatenating N 'a' times?
2016-02-21 09:25:38 Ankit
the answers need to be in the single line, or on separate lines ? Little confusing.

Last edit: 2016-02-21 09:25:47
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.