URI Online Judge | 1280

Friends

By Humberto Longo, UFG Brazil

Timelimit: 1

John will help his friend Joseph in a hard and laborious task, but they still not reach an agreement on the John’s payment by the aid in the task. After some discussion, John, who is very good at math, proposed the following: initially each one will define, without the other knowing it, a certain value, i.e. John will define a value n and Joseph will define a value m. So if Joseph propose do not to pay anything, then he will have to pay n + 1 dollars! If John say that do not want to receive anything and Joseph propose paying 1 or more dollars, Joseph will pay the same amount that would pay if John had asked for a dollar and Joseph had proposed to pay only m - 1 dollars! If both values are greater than zero, Joseph will pay the same value that would have to pay if he had proposed m - 1 dollars and John wanted to receive the same that would receive if Joseph had proposed to pay m dollars and he had asked for n - 1 dollars!! They also agreed that if Joseph was willing to pay at most 3 dollars, then John could charge up to 200 dollars. On the other hand, if Joseph was willing to pay 4 dollars, then John only could charge up to 2 dollars! After hours discussing these rules, they finally agreed that it would be too laborious calculate the amount owed by Joseph. So write a program that calculates the amount of dollars Joseph will have to pay to John, according to these rules.

Input

The first line of the input contains an integer T that indicates the number of test cases. The T following lines contain two integers (0 ≤ ≤ 4) and (0 ≤ ≤ 200), separated by a space, representing the values that Joseph want to pay and John want to receive, respectively.

Output

The output should contain, for each test case, an integer equal to the value that Joseph will have to pay to John.

Sample Input Sample Output

4
0 1
1 0
1 1
2 1

2
2
3
5