There are balls in a box. You have two robots Alice and Bob. You will set favorite number for each of them. Both of their favorite numbers are positive integer, not exceeding . Say, Alice’s favorite number is set as and Bob’s favorite number is set as . Now, they move alternatingly. Alice moves first.
On Alice’s move, it takes exactly balls from the box. On Bob’s move, it takes exactly balls from the box. If someone cannot complete its move, the game stops.
You know your favorite integer is . That’s why, you will set the values of and in such a way that and the box will not contain any ball in the end. Remember both of and are positive integers, not exceeding .
What is the maximum number of total moves the robots can perform, if you set the values of and satisfying the given conditions? It can be shown that there is at least one way of setting the values of and exists satisfying the given conditions.
First line will have one integer , denoting the number of testcases.
Each of the next lines will have two integers and , describing the testcase.
Output one line for each testcase, consisting maximum possible number of total moves.
2 10 3 7 2
For first testcase, you can set and . There will be moves in total.
Note that, if you set and , after moves, there will be ball in the box. Alice cannot perform his move from here and the game ends. So, you cannot set and in this case.
You could set and . That would result in total move. But it is not optimal here.