#P1615B. And It's Non-Zero
And It's Non-Zero
No submission language available for this problem.
Description
You are given an array consisting of all integers from inclusive. For example, if and , the array would be . What's the minimum number of elements you can delete to make the bitwise AND of the array non-zero?
A bitwise AND is a binary operation that takes two equal-length binary representations and performs the AND operation on each pair of the corresponding bits.
The first line contains one integer () — the number of test cases. Then cases follow.
The first line of each test case contains two integers and () — the description of the array.
For each test case, output a single integer — the answer to the problem.
Input
The first line contains one integer () — the number of test cases. Then cases follow.
The first line of each test case contains two integers and () — the description of the array.
Output
For each test case, output a single integer — the answer to the problem.
Samples
Note
In the first test case, the array is . Currently, the bitwise AND is , as . However, after deleting (or ), the array becomes (or ), and the bitwise AND becomes (or ). This can be proven to be the optimal, so the answer is .
In the second test case, the array is . Currently, the bitwise AND is . However, after deleting , , and , the array becomes , and the bitwise AND becomes . This can be proven to be the optimal, so the answer is . Note that there may be other ways to delete elements.