
Fig. 1: An example of FBT with the maximum depth 4 and sequential node numbers.
Now consider a number of test cases where two values will be given for each test. The first value is D, the maximum depth of FBT, and the second one is I, the I-th ball being dropped. You may assume the value of I will not exceed the total number of leaf nodes for the given FBT.
Please write a program to determine the stop position P for each test case.
For each test cases the range of two parameters D and I is as below:
2 ≤ D ≤ 20, and 1 ≤ I ≤ 524288.
Contains l + 2 lines.
| Line | Value | Description |
|---|---|---|
| Line 1 | l | the number of test cases |
| Line 2 | D1 I1 | test case #1, two decimal numbers that are separated by one blank |
| ... | ||
| Line k + 1 | Dk Ik | test case #k |
| Line l + 1 | Dl Il | test case #l |
| Line l + 2 | -1 | a constant ‘-1’ representing the end of the input file |
Contains l lines.
| Line | Description |
|---|---|
| Line 1 | the stop position P for the test case #1 |
| ... | |
| Line k | the stop position P for the test case #k |
| ... | |
| Line l | the stop position P for the test case #l |