Problem Statement
There is an array A1,ldots,AN, and initially Ai=i for all i. Define the following routine mathrmshuffle(L,R):
- If R=L+1, swap values of AL and AR and terminate.
- Otherwise, run mathrmshuffle(L,R−1) followed by mathrmshuffle(L+1,R).
Suppose we run mathrmshuffle(1,N). Print the value of AK after the routine finishes.
For each input file, solve T test cases.
Constraints
- 1leqTleq1000
- 2leqNleq1018
- 1leqKleqN
The input is given from Standard Input in the following format:
T
case1
case2
vdots
caseT
Each case is in the following format:
N K
Output
Print T lines. The i-th line should contain the answer for the i-th case.
7
2 1
2 2
5 1
5 2
5 3
5 4
5 5
Sample Output 1
2
1
2
4
1
5
3
For N=2, we do the following and get A=(2,1).
- Run mathrmshuffle(1,2), and swap A1 and A2.
For N=5, we do the following and get A=(2,4,1,5,3).
- Run mathrmshuffle(1,5):
- Run mathrmshuffle(1,4):
- Run mathrmshuffle(1,3):
- Run mathrmshuffle(2,4):
- Run mathrmshuffle(2,5):
- Run mathrmshuffle(2,4):
- Run mathrmshuffle(3,5):