GCD2 - GCD2


Frank explained its friend Felman the algorithm of Euclides to calculate the GCD of two numbers. Then Felman implements it algorithm

int gcd(int a, int b)
{
	if (b==0)
		return a;
	else
		return gcd(b,a%b);
}
and it proposes to Frank that makes it but with a little integer and another integer that has up to 250 digits.

Your task is to help Frank programming an efficient code for the challenge of Felman.

Input

The first line of the input file contains a number representing the number of lines to follow. Each line consists of two number A and B (0 <= A <= 40000 and A <= B < 10^250).

Output

Print for each pair (A,B) in the input one integer representing the GCD of A and B.

Example

Input:
2
2 6
10 11

Output:
2
1

Source limit is 1,000 Bytes.


hide comments
malcolm123_ssj: 2018-11-17 18:54:59

don't think much. use python to solve such questions

prachij: 2018-10-03 20:57:34

AC in one go in Python 3 with 4 lines of code :D

mynk322: 2018-09-19 15:41:38

REMEMBER!!!!
gcd of a,0 is a.
gcd of 0,b is b.
cost me 2 WA!!

imkiller: 2018-06-01 13:59:52

Python AC in oneGo!

pithoriya: 2018-02-14 18:44:42

use Boost ....

sinersnvrsleep: 2017-12-18 11:58:13

easy in c++ too will make the concepts more clear try it

madhur4127: 2017-09-02 16:44:00

piece of cake in python!

shauryauppal: 2017-07-06 19:50:26

Input in string would give u wrong answer
While input in a char array of size 300 would give you AC.

one_mole: 2017-06-26 16:48:13

corner case A = 0.

ankit1cool: 2017-06-13 12:20:36

cake walk using python


Added by:Frank Rafael Arteaga
Date:2008-08-04
Time limit:0.25s
Source limit:1000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: C99 LISP clisp LISP sbcl ERL JAVA JS-RHINO NODEJS PERL PERL6 PHP PYTHON RUBY VB.NET
Resource:My own Resource