#include <bits/stdc++.h>
using namespace std;
int n;
int dig(long long x) {
  if (!x) return 1;
  int c = 0;
  while (x) {
    x /= 2;
    ++c;
  }
  return c;
}
long long max_pop(long long l, long long r) {
  if (l == r) return l;
  int d = dig(r);
  long long val = 1LL << d;
  if (val > r) val >>= 1;
  long long v_tmp = val;
  if (val <= l) return max_pop(l - val, r - val) + val;
  val = (v_tmp << 1) - 1;
  if (val <= r) return val;
  return v_tmp - 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    long long l, r;
    cin >> l >> r;
    cout << max_pop(l, r) << endl;
  }
  return 0;
}
