#ABC476G. 递增的 popcount / Increasing Popcount

递增的 popcount / Increasing Popcount

Problem Statement

You are given positive integers LL and RR satisfying L≤RL\le R.

A sequence of positive integers A=(AL,AL+1,…,AR)A=(A_L,A_{L+1},\ldots,A_R) of length R−L+1R-L+1 satisfying the following condition is called a good integer sequence:

  • For every pair of integers (i,j)(i,j) satisfying L≤i<j≤RL\le i < j\le R, if Ai=AjA_i = A_j, then $\operatorname{popcount}(i)<\operatorname{popcount}(j)$.

Find the minimum value of max⁡(AL,AL+1,…,AR)\max(A_L,A_{L+1},\ldots,A_R) over all good integer sequences A=(AL,AL+1,…,AR)A=(A_L,A_{L+1},\ldots,A_R).

You are given TT test cases; solve each of them.

What is popcount⁡\operatorname{popcount}? For a non-negative integer xx, popcount⁡(x)\operatorname{popcount}(x) is the number of 11's when xx is written in binary. More precisely, when a non-negative integer xx satisfies $\displaystyle x=\sum _ {i=0} ^ \infty b _ i2 ^ i\ (b _ i\in\lbrace0,1\rbrace)$, $\displaystyle\operatorname{popcount}(x)=\sum _ {i=0} ^ \infty b _ i$.

For example, 1313 written in binary is 1101, so popcount⁡(13)=3\operatorname{popcount}(13)=3.

Constraints

  • 1≤T≤1041\le T\le 10^4
  • 1≤L≤R≤10181\le L \le R\le 10^{18}
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

  • TT
  • case1\text{case}_1
  • case2\text{case}_2
  • ⋮\vdots
  • caseT\text{case}_T

Each test case is given in the following format.

  • LL RR

Output

Output TT lines.

The ii-th line (1≤i≤T)(1\le i\le T) should contain the answer for the ii-th test case casei\text{case}_i.

5
3 6
1 1
2 15
100 10000000
514284786278117031 620546740167642909
3
1
6
1636985
11375123021856567

Consider the first test case.

(A3,A4,A5,A6)=(1,2,2,3)(A_3,A_4,A_5,A_6)=(1,2,2,3) is a good integer sequence, and max⁡(A3,A4,A5,A6)=3\max(A_3,A_4,A_5,A_6)=3.

There is no good integer sequence with max⁡(A3,A4,A5,A6)<3\max(A_3,A_4,A_5,A_6) < 3, so output 33 on the first line.