Alice recently converted all the positive integers from
to (both inclusive) into binary strings and stored them in an array . Note that the binary strings do not have leading zeroes.
While she was out, Bob sorted all the elements of in lexicographical increasing order.
Let denotes the string in the sorted array.
Alice defined a function such that is equal to the count of in the string .
For example, and .
Given a positive integer , find the value of .
String is lexicographically smaller than string if one of the following satisfies:
- is a prefix of and .
- There exists an index such that and for all , .
Input Format
- The first line will contain an integer - number of test cases. Then the test cases follow.
- The first and only line of each test case contains two integers and .
Output Format
For each test case, output the value .
Constraints
- Sum of over all test cases does not exceed .
Sample Input 1
3
3 2
3 4
3 7
Sample Output 1
2
5
12
Explanation
Converting positive integers to Binary Strings:
Sorting Binary Strings in lexicographical order: After sorting, the strings will appear in the following order:
.
Test case : .
Test case :
ConversionConversion EmoticonEmoticon