#C5162. Largest Square from a Rectangular Board

    ID: 48781 Type: Default 1000ms 256MiB

Largest Square from a Rectangular Board

Largest Square from a Rectangular Board

You are given a rectangular board with dimensions L (length) and W (width). The task is to determine the side length of the largest square that can be cut from the board without any leftover.

This is equivalent to finding the greatest common divisor (gcd) of L and W. In mathematical terms, the side length is given by:

$$ \text{side} = \gcd(L, W) $$

Read the input from standard input (stdin) and output the answer to standard output (stdout) for each test case.

inputFormat

The input begins with an integer T representing the number of test cases. Each of the next T lines contains two positive integers L and W representing the dimensions of the board.

Example:

3
6 9
10 15
7 5

outputFormat

For each test case, output a single integer in a separate line representing the side length of the largest square that can be formed from the board.

Example:

3
5
1
## sample
1
6 9
3

</p>