#P1588. [USACO07OPEN] Catch That Cow S

[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 xx and yy, and the cow stays put. In each move, if FJ is at position pp, he can move to p+1p + 1, p1p - 1, or 2×p2 \times p. Compute the minimum number of moves needed for FJ to catch the cow.

Input Format

The first line contains an integer tt ( 1t101 \le t \le 10 ), the number of test cases.

Each of the next tt lines contains two positive integers x,yx, y ( 0<x,y1050 < 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.

1 
5 17
4

Hint

Translated by ChatGPT 5