CF1657A.Integer Moves

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Integer Moves

There's a chip in the point (0,0)(0, 0) of the coordinate plane. In one operation, you can move the chip from some point (x1,y1)(x_1, y_1) to some point (x2,y2)(x_2, y_2) if the Euclidean distance between these two points is an integer (i.e. qrt(x1−x2)2+(y1−y2)2qrt{(x_1-x_2)^2+(y_1-y_2)^2} is integer).

Your task is to determine the minimum number of operations required to move the chip from the point (0,0)(0, 0) to the point (x,y)(x, y).

Input

The first line contains a single integer tt (1≤t≤30001 \le t \le 3000) — number of test cases.

The single line of each test case contains two integers xx and yy (0≤x,y≤500 \le x, y \le 50) — the coordinates of the destination point.

Output

For each test case, print one integer — the minimum number of operations required to move the chip from the point (0,0)(0, 0) to the point (x,y)(x, y).

Note

In the first example, one operation (0,0)→(8,6)(0, 0) \rightarrow (8, 6) is enough. qrt(0−8)2+(0−6)2=qrt64+36=qrt100=10qrt{(0-8)^2+(0-6)^2}= qrt{64+36}= qrt{100}=10 is an integer.

In the second example, the chip is already at the destination point.

In the third example, the chip can be moved as follows: (0,0)→(5,12)→(9,15)(0, 0) \rightarrow (5, 12) \rightarrow (9, 15). qrt(0−5)2+(0−12)2=qrt25+144=qrt169=13qrt{(0-5)^2+(0-12)^2}= qrt{25+144}= qrt{169}=13 and qrt(5−9)2+(12−15)2=qrt16+9=qrt25=5qrt{(5-9)^2+(12-15)^2}= qrt{16+9}= qrt{25}=5 are integers.

Samples

3
8 6
0 0
9 15
1
0
2

在线编程 IDE

建议全屏模式获得最佳体验