#include <bits/stdc++.h>   using namespace std;   string tobinary(long long x) {     string ret;     char ch;     while (x) ch =  0  + (x % 2), ret = ch + ret, x /= 2;     return ret;   }   long long todecimal(string s) {     int sz = s.size();     long long ret = 0;     for (int i = 0; i < sz; i++) ret = 2 * ret + (s[i] -  0 );     return ret;   }   bool _greater(string s, string t) {     int n = s.size(), m = t.size();     if (n > m) return true;     if (n < m) return false;     for (int i = 0; i < n; i++) {       if (s[i] > t[i])         return true;       else if (s[i] < t[i])         return false;     }     return false;   }   long long eval(long long l, long long r) {     string s = tobinary(l), t = tobinary(r), ret = s;     while (1) {       if (_greater(s, t)) break;       ret = s;       int sz = s.size();       bool ok = false;       for (int i = sz - 1; i >= 0; i--)         if (s[i] ==  0 ) {           s[i] =  1 ;           ok = true;           break;         }       if (!ok) {         s =  1  + s;         int n = s.size(), m = t.size();         if (n > m) break;       }     }     return todecimal(ret);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     while (n--) {       long long l, r;       cin >> l >> r;       cout << eval(l, r) << endl;     }     return 0;   }   