#include<bits/stdc++.h>
#define int long long
using namespace std;
int t,l,r,s;
signed main(){
cin.tie(nullptr)->sync_with_stdio(0);
cin>>t;
while(t--){
s=0;
cin>>l>>r;
for(int p=1;p<=61;p++){
if((r>>p-1)-(r>>p)!=(l>>p-1)-(l>>p)){
s++;
}
}
cout<<(1ll<<s)-1<<'\n';
}
return 0;
}