Welcome to the China Collegiate Programming Contest (CCPC) Zhengzhou onsite! Bobo has noticed that the initials of "Zheng" and "Zhou" are both Z. This motivates him to study the well-known Z-order curve.
To introduce the Z-order curve, we first introduce the Moser–de Bruijn sequence $$$(B_t)_{t \ge 0}$$$, the ordered sequence of numbers whose binary representation has nonzero digits only in the even positions. The first few terms of the Moser-de Bruijn sequence are $$$0, 1, 4, 5, 16, 17, 20, 21$$$.
Each non-negative integer $$$z$$$ can be uniquely decomposed into the sum of $$$B_x$$$ and $$$2B_y$$$. Therefore, we can write down all natural numbers in an infinitely large table. The Z-order curve is then obtained by connecting all the numbers in numerical order.
![]() |
Bobo now challenges you with the following problem: For a given fragment extracted from the Z-curve from $$$L$$$ to $$$R$$$, find the smallest integer $$$l$$$ such that the Z-curve from $$$l$$$ to $$$l+R-L$$$ is identical to the given fragment (i.e., the curve from $$$l$$$ to $$$l+R-L$$$ can be obtained by translating the curve from $$$L$$$ to $$$R$$$).
Please note that in this problem, the curve is directed. Specifically, the curve from $$$1$$$ to $$$2$$$ is NOT identical to the curve from $$$3$$$ to $$$4$$$.
The first line of the input contains a single integer $$$T$$$ ($$$1 \le T \le 100$$$), denoting the number of test cases.
The first and only line of each test case contains two integers $$$L$$$ and $$$R$$$ ($$$0 \le L \lt R \le 10^{18}$$$).
For each test case, output the answer in one line.
417 200 6338 40998244353998244353 998244853998244853
1 0 6 2145186925057
The following figure illustrates the Z-curve for the first and third test cases in the sample.
![]() |
| Name |
|---|


