#P1814B. Long Legs
Long Legs
No submission language available for this problem.
Description
A robot is placed in a cell of an infinite grid. This robot has adjustable length legs. Initially, its legs have length .
Let the robot currently be in the cell and have legs of length . In one move, it can perform one of the following three actions:
- jump into the cell ;
- jump into the cell ;
- increase the length of the legs by , i. e. set it to .
What's the smallest number of moves robot has to make to reach a cell ?
The first line contains a single integer () — the number of test cases.
The only line of each test case contains two integers and () — the ending cell.
For each test case, print a single integer — the smallest number of moves the robot is required to make to reach a cell from a cell .
Input
The first line contains a single integer () — the number of test cases.
The only line of each test case contains two integers and () — the ending cell.
Output
For each test case, print a single integer — the smallest number of moves the robot is required to make to reach a cell from a cell .
Note
In the first testcase, the robot can first jump to , then to . If it ever increases the length of its legs, it will only be able to jump past .
In the second testcase, the robot can jump to , then increase the length of its length to and jump three times to reach .
In the third testcase, the robot can increase the length of its legs three times to make it . Then jump to . Then jump twice to reach .