问题 J: Rikka with Square Numbers

内存限制:246 MB 时间限制:1 S
题面:传统 评测方式:文本比较 上传者:
提交:2 通过:2

题目描述

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, a, into another, b, where �≠�a=b. In a single operation, Rikka can either add a positive square number to a, or subtract a positive square number from a. The goal is to convert a into b by executing the least number of operations.

A square number is an integer that is the product of some integer with itself. For example, 114499, and 1616 are square numbers, as they are the squares of 112233, and 44, respectively.

The problem might seem complex for Rikka. Can you assist Rikka in solving this?

输入格式

The first line contains one integer T (1≤�≤1031T103), indicating the number of test cases.

For each test case, the only line contains two integers �,�a,b (1≤�,�≤1091a,b109�≠�ab).

输出格式

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

输入样例 复制

2
1 4
5 1

输出样例 复制

2
1

数据范围与提示

Consider the first sample where Rikka can add 22=422=4 to a, and then subtract 12=112=1 from a. After executing two operations, a becomes 44.