#4. 遞推數列 Recurrence sequence

Memory limit: 256 MiB Time limit: 1000 ms Input file: stdin Output file: stdout
Problem type: traditional Judging mode: text compare
Uploded by root

Description

定義遞推數列:

a_n= \begin{cases} 0& n=0\\ \left \lfloor \frac{a_{\left \lfloor \frac{n}{2} \right \rfloor}}{2} \right \rfloor\ \lor \ \left ( (n\bmod 2)\times 2 ^{m}\right) & n \geq 1 \end{cases}

其中, \left \lfloor x \right \rfloor 表示向下取整, x \lor \ y 表示整數 x y 按位或後的結果。

對於給定的 m,k ,求 a_k 的值。


Define a recurrence sequce a as follows,

a_n= \begin{cases} 0& n=0\\ \left \lfloor \frac{a_{\left \lfloor \frac{n}{2} \right \rfloor}}{2} \right \rfloor\ \lor \ \left ( (n\bmod 2)\times 2^{m}\right) & n \geq 1 \end{cases}

where \lfloor x \rfloor gives the greatest integer that is less than or equal to x as an output, "\lor" represents the bitwise-or operator.

Please find a_k given m, k .

Input

輸入數據共 T+1 行。

第一行一個整數 T ,表示數據組數。接下來 T 行,每行兩個整數 m,k ,含義如題面所示。


The input contains many test cases. The first line of the input contains an integer T , indicating the number of test cases.

In the following T lines, each line contains two integers m and k , separated by a space, the meanings of which are as shown above.

Output

T 行,每一行一個整數,分別表示每組數據的答案。


Write T lines in total; each line of the output contains an integer, indicating the answer to the corresponding test case, i.e., a_k .

Sample

Sample 1 input

2
10 0
2 3

Sample 1 output

0
6

Sample 1 explanation

對於第一組樣例: a_0=0

對於第二組樣例: a_0=0,a_1=4,a_2=2,a_3=6

In the first test case, a_0=0 .

In the second test case, a_0=0,a_1=4,a_2=2,a_3=6 .

Constraint and hint

對於全部測試數據,滿足 1 \leq T\leq 3\times 10^5,0\leq m\leq 60,0\leq k \leq 2^{m+1}

子任務 分數 附加限制
1 40 \sum 2^m\le 1048576
2 60 無附加限制

For all test data, 1 \leq T\leq 3\times 10^5,0\leq m\leq 60,0\leq k \leq 2^{m+1} .

Subtask Score Additional constraints
1 40 \sum 2^m\le 1048576
2 60 No additional constraints