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
gurugs: 2016-03-02 04:10:56

comments were helpful

street_funker: 2016-03-01 21:32:30

A simple relation ,try few custom test case

ATUL KUMAR SINGH: 2016-02-26 12:39:24

simple but after 9 wa of common mistake ac

Last edit: 2016-02-26 12:39:43
ghost_wire: 2016-02-25 20:36:41

why i am getting WA ?
test case plss..

[Lakshman]: 2016-02-25 18:45:04

@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) .

dwij28: 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. :)

[Lakshman]: 2016-02-23 08:36:42

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
farhan764: 2016-02-23 07:45:13

N 'a' times mean concatenates N 'a' times

Shivam Garg: 2016-02-22 21:34:18

does repeating N 'a' times mean X=N*a , or concatenating N 'a' times?

Ankit: 2016-02-21 09:25:38

the answers need to be in the single line, or on separate lines ? Little confusing.

Last edit: 2016-02-21 09:25:47

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