B. Binary Sequence
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

A well-known puzzle is: "what is the next element in the sequence $$$1, 11, 21, 1211, 111221, 312211$$$?". In this problem we consider the binary variant.

The first element of the binary look and say sequence is 1. Each next element is generated by looking at the previous element and counting the number of digits in each group of consecutive similar digits. For example, if an element of the sequence is 110001, then the next element will be 10111011 (10 1, 11 0, 1 1, that is: two 1s, three 0s, one 1). Notice that the counts of similar digits are written down in binary.

For example, the first few elements of the sequence are generated as follows:

  • 1 is read as "one 1", thus the second element is 11.
  • 11 is read as "two 1s" i.e. "10 1", thus the third element is 101.
  • 101 is read as "one 1, one 0, one 1", i.e, "1 1, 1 0, 1 1", thus the fourth element is 111011.
  • 111011 is read as "three 1-s, one 0, two 1-s", i.e. "11 1, 1 0, 10 1", thus the fifth element is 11110101.

Your task is to calculate the $$$m$$$-th binary digit from the right of the $$$n$$$-th element in the sequence. The first element of the sequence has index 1; the rightmost binary digit of an element has index 0. If the element has $$$m$$$ or fewer binary digits, output 0.

Input

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. $$$t$$$ test cases follow.

Each test case consists of two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 10^{18}$$$, $$$0 \le m \lt 10^6$$$).

Output

For each test case, print the answer on a separate line.

Example
Input
10
4 0
4 1
4 2
4 3
4 4
4 5
4 6
6 3
6 7
118999881999119725 3
Output
1
1
0
1
1
1
0
1
1
0
Note

The fourth element of the sequence is 111011. The first six tests print out this number in reverse: as we are increasing $$$m$$$, we are moving from right to left. The seventh test, 4 6 returns 0 as there are only six digits in the number 111011.