#include <bits/stdc++.h>
using namespace std;
inline int countBits(unsigned long long n) {
  int r = 0;
  while (n) {
    r++;
    n = n >> 1;
  }
  return r;
}
inline int count1(unsigned long long n) {
  int r = 0;
  while (n) {
    if (n & 1) {
      r++;
    }
    n = n >> 1;
  }
  return r;
}
unsigned long long all[64];
unsigned long long run() {
  unsigned long long l, r;
  cin >> l >> r;
  int cr = countBits(r);
  int cl = countBits(l);
  if (cr == count1(r)) {
    return r;
  } else if (cl == cr) {
    unsigned long long diff = l ^ r;
    int dc = countBits(diff);
    unsigned long long base = ((l >> dc) << dc);
    if (all[dc] == r - base) {
      return r;
    }
    return ((l >> dc) << dc) + all[dc - 1];
  } else {
    return all[cr - 1];
  }
}
int main() {
  ios::sync_with_stdio(0);
  unsigned long long op = 0;
  all[0] = 0;
  for (int i = 1; i < 64; i++) {
    op = op << 1;
    op += 1;
    all[i] = op;
  }
  int t;
  cin >> t;
  while (t--) {
    cout << run() << endl;
  }
  return 0;
}
