#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t, l, r, i;
  cin >> t;
  while (t--) {
    cin >> l >> r;
    bitset<64> a(l);
    i = 0;
    while (i < 64) {
      if (a[i] == 0) {
        a[i] = 1;
        if (a.to_ullong() > r) {
          a[i] = 0;
          break;
        }
      }
      i++;
    }
    cout << a.to_ullong() << "\n";
    ;
  }
}
