NINJA3 - STUNNING GCD

no tags 

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

hide comments
farhan764: 2016-02-21 08:30:08

@dungeon_master:=> would u plz provide output of these test cases

Siddharth Singh: 2016-02-21 07:12:09

Easy , AC in 1 Go
@azam
Try these test cases
12 4 6
7 3 5
177 3 9
these 3 are enough to decipher to logic for this problem
@farhan764, if i type the output u will instantly get the logic
if u really want to solve this problem
create a gcd function , giv it the inputs i have specific making X and Y.
u'll get the logic . all the best
@ankit
the output has to be on a new line for every test case just like for any other problem on SPOJ

Last edit: 2016-02-21 11:24:57
azam_9: 2016-02-20 16:01:34

dont knw y i m getting WA..plz give some tricky test cases.


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