P11062 [MX-X4-T2] "Jason-1" Addition.

Background

Original link: 。

Description

Given two integers $a, b$ (possibly negative), you may perform any number of operations (including doing nothing). In each operation, you need to choose one of the following two forms: - Operation 1: Assign $a$ to the sum of $a$ and $b$, i.e., $a \gets a + b$. - Operation 2: Assign $b$ to the sum of $a$ and $b$, i.e., $b \gets a + b$. Your goal is to minimize the absolute value of the difference between $a$ and $b$, $\lvert a-b \rvert$. Output the minimum value.

Input Format

**This problem contains multiple test cases.** The first line contains a positive integer $T$, the number of test cases. For each test case: - One line containing two integers $a, b$.

Output Format

For each test case: - Output one integer on a single line, the answer.

Explanation/Hint

**[Sample Explanation #1]** For the 1st test case, one feasible plan is: perform no operations, and $\lvert a-b \rvert=0$. For the 2nd test case, one feasible plan is: first use operation 2, so $b$ is assigned to $10$; then use operation 1, so $a$ is assigned to $13$. At this time, $\lvert a-b \rvert=3$. It can be proven that this is the minimum value achievable. For the 3rd test case, one feasible plan is: use operation 1 consecutively $5$ times, and $a$ is assigned to $-3,-2,-1,0,1$ in order. At this time, $a$ and $b$ are equal, so $\lvert a-b \rvert=0$. For the 4th test case, one feasible plan is: perform no operations, and $\lvert a-b \rvert=3$. For the 5th test case, one feasible plan is: use operation 2, so $b$ is assigned to $4$. At this time, $\lvert a-b \rvert=0$. **[Sample Explanation #2]** For both test cases in this sample, you can first use operation 2 once, then use operation 1 three times, making the absolute difference $0$. **[Constraints]** | Test Point ID | Special Property | Score | | :----------: | :----------: | :----------: | | 1 | A | $27$ | | 2 | B | $31$ | | 3 | None | $42$ | - Special Property A: $\lvert a \rvert, \lvert b \rvert \le 10$ is guaranteed. - Special Property B: $a,b \ge 1$ is guaranteed. For $100\%$ of the testdata, $1 \le T \le 10^5$, $\lvert a \rvert, \lvert b \rvert \le 10^9$. Translated by ChatGPT 5