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
agarwalg271: 2016-08-16 11:55:39

ya i totally agree with coder_hsnake

vineetpratik: 2016-07-03 19:18:45

esy one if u got the question right!

manjur1996: 2016-06-23 09:36:35

easy go, once u get the logic

Francky: 2016-06-09 21:09:30

@LeBron : I tried an awaited solution and got AC. I tried a weaker code and got TLE. What kind of input would you like to see here. We obviously can't wait in output a 1.8e19 - length number.
Please give a good sample of input that you think is absent.

LeBron: 2016-06-09 13:50:59

SPOJ turns into rubbish because of setters providing problems like this one. There are clearly no good test data here, so "constraints" section makes no sense.

akshayvenkat: 2016-05-30 11:29:35

i/p:
2
123 2 4
123 3 9

o/p
123123
123123123

ragwave: 2016-05-17 20:55:34

do run test cases on this to get what question is actually saying
http://www.spojtoolkit.com/test/NINJA3
Question would hav been more logical if it meant X=N*a and Y=N*b,
but here it says X=NNNNNN....a times and Y=NNNNN......b times

aryan_r: 2016-03-08 20:35:07

N can be a larger number

pk: 2016-03-03 23:23:29

Cake walk.

Mayank Garg: 2016-03-03 03:44:26

Easy one .. But nyc logic :D


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