/**
* Created by ckboss on 14-11-7.
*/
import java.util.*;
public class CF484A
{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int T_T = in.nextInt();
while (T_T-- > 0) {
long l = in.nextLong(), r = in.nextLong();
long low=0;
while(true) {
int mid = -1;
long low_leve=-1;
for (int i = 0; i <= 60; i++) {
long temp=(1L << i) - 1L;
if(temp>r) break;
if ( temp >= l && temp <= r) {
mid = i;
}
if(temp < l){
low_leve=temp;
}
}
if (mid != -1) {
System.out.println((1L << mid) - 1L+low);
break;
}
else{
low_leve++;
low+=low_leve;
l-=low_leve; r-=low_leve;
}
}
}
}
}