#agc061a. [agc061_a]Long Shuffle

[agc061_a]Long Shuffle

Problem Statement

There is an array A1,ldots,ANA_1, \\ldots, A_N, and initially Ai=iA_i = i for all ii. Define the following routine mathrmshuffle(L,R)\\mathrm{shuffle}(L, R):

  • If R=L+1R = L + 1, swap values of ALA_L and ARA_R and terminate.
  • Otherwise, run mathrmshuffle(L,R1)\\mathrm{shuffle}(L, R - 1) followed by mathrmshuffle(L+1,R)\\mathrm{shuffle}(L + 1, R).

Suppose we run mathrmshuffle(1,N)\\mathrm{shuffle}(1, N). Print the value of AKA_K after the routine finishes.

For each input file, solve TT test cases.

Constraints

  • 1leqTleq10001 \\leq T \\leq 1000
  • 2leqNleq10182 \\leq N \\leq 10^{18}
  • 1leqKleqN1 \\leq K \\leq N

Input

The input is given from Standard Input in the following format:

TT case1case_1 case2case_2 vdots\\vdots caseTcase_T

Each case is in the following format:

NN KK

Output

Print TT lines. The ii-th line should contain the answer for the ii-th case.


Sample Input 1

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=2N=2, we do the following and get A=(2,1)A=(2,1).

  • Run mathrmshuffle(1,2)\\mathrm{shuffle}(1, 2), and swap A1A_1 and A2A_2.

For N=5N=5, we do the following and get A=(2,4,1,5,3)A=(2,4,1,5,3).

  • Run mathrmshuffle(1,5)\\mathrm{shuffle}(1, 5):
    • Run mathrmshuffle(1,4)\\mathrm{shuffle}(1, 4):
      • Run mathrmshuffle(1,3)\\mathrm{shuffle}(1, 3):
        • vdots\\vdots
      • Run mathrmshuffle(2,4)\\mathrm{shuffle}(2, 4):
        • vdots\\vdots
    • Run mathrmshuffle(2,5)\\mathrm{shuffle}(2, 5):
      • Run mathrmshuffle(2,4)\\mathrm{shuffle}(2, 4):
        • vdots\\vdots
      • Run mathrmshuffle(3,5)\\mathrm{shuffle}(3, 5):
        • vdots\\vdots