P1588 [USACO07OPEN] Catch That Cow S

Description

FJ lost one of his cows and decided to get it back. FJ and the cow are on a number line with initial positions $x$ and $y$, and the cow stays put. In each move, if FJ is at position $p$, he can move to $p + 1$, $p - 1$, or $2 \times p$. Compute the minimum number of moves needed for FJ to catch the cow.

Input Format

The first line contains an integer $t$ ( $1 \le t \le 10$ ), the number of test cases. Each of the next $t$ lines contains two positive integers $x, y$ ( $0 < x, y \le 10^5$ ), representing the coordinates of FJ and the cow, respectively.

Output Format

For each test case, output the minimum number of moves.

Explanation/Hint

Translated by ChatGPT 5