#K83097. Largest Square Side

    ID: 36121 Type: Default 1000ms 256MiB

Largest Square Side

Largest Square Side

You are given several rectangular sheets, each with width W and height H. Your task is to determine the side length of the largest square that can be used to completely cover the rectangle without any overlap or cutting. Mathematically, you are asked to compute the greatest common divisor (GCD) of W and H for each rectangle.

The largest square's side length is given by \(\gcd(W, H)\). For example, a rectangle of dimensions 8 x 12 can be exactly tiled with squares of side \(\gcd(8, 12) = 4\).

You will be given multiple test cases. For each test case, read the dimensions of the rectangle and print the computed side length (GCD) as output, one per line.

inputFormat

The input begins with an integer T representing the number of test cases. Each test case consists of a single line containing two space-separated integers W and H, the width and height of the rectangle respectively.

For example:

3
2 2
7 3
8 12

outputFormat

For each test case, output a single line containing the side length of the largest square that can completely cover the rectangle. This is the greatest common divisor of W and H.

For the sample input above, the output should be:

2
1
4
## sample
3
2 2
7 3
8 12
2

1 4

</p>