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