#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long i, d, l, r, n;
    cin >> l >> r;
    d = log2(r);
    i = pow(2, d + 1);
    d = pow(2, d) - 1;
    if ((r + 1) == i)
      cout << r;
    else if (d <= r && d >= l)
      cout << d;
    else {
      i = 1;
      n = 1;
      while (l + n <= r) {
        if ((n ^ l) > l) {
          l = l + n;
        }
        n = pow(2, i++);
      }
      cout << l;
    }
    cout << endl;
  }
  return 0;
}
