#P9886. Rikka with Square Numbers

Rikka with Square Numbers

Rikka with Square Numbers

Problem Description

Rikka struggles with math. Observing this, Yuta decides to help her improve by assigning some math practice tasks. Here is one such task. The task requires transforming one integer, aa, into another, bb, where aba \neq b. In a single operation, Rikka can either add a positive square number to aa, or subtract a positive square number from aa. The goal is to convert aa into bb by executing the least number of operations. A square number is an integer that is the product of some integer with itself. For example, 11, 44, 99, and 1616 are square numbers, as they are the squares of 11, 22, 33, and 44, respectively. The problem might seem complex for Rikka. Can you assist Rikka in solving this?

Input

The first line contains one integer TT (1T1031\le T\le 10^3), indicating the number of test cases. For each test case, the only line contains two integers a,ba,b (1a,b1091\le a,b\le 10^9, aba\neq b).

Output

For each test case, output a single line containing one integer, indicating the minimum number of operations required.

Sample Input

2
1 4
5 1

Sample Output

2
1

Hint

Consider the first sample where Rikka can add 22=42^2=4 to aa, and then subtract 12=11^2=1 from aa. After executing two operations, aa becomes 44.

Source

2023“钉耙编程”中国大学生算法设计超级联赛(8)