#include <bits/stdc++.h>
using namespace std;
uint64_t p2[64];
uint64_t findPow(uint64_t a) {
  uint64_t i = 0;
  while (a > 0) {
    i += 1;
    a /= 2;
  }
  return i - 1;
}
uint64_t find(uint64_t l, uint64_t r) {
  if (l == 0 && r == 0) return 0;
  if (l == 0) l += 1;
  uint64_t lp = findPow(l);
  uint64_t rp = findPow(r);
  if (r == p2[rp + 1] - 1) {
    return r;
  } else if (lp < rp) {
    return p2[rp] - 1;
  } else {
    return p2[lp] + find(l - p2[lp], r - p2[rp]);
  }
  return 0;
}
int main(int, char**) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  uint64_t p = 1;
  for (uint64_t i = 0; i < 64; ++i) {
    p2[i] = p;
    p *= 2;
  }
  uint64_t n, l, r;
  cin >> n;
  for (uint64_t i = 0; i < n; ++i) {
    cin >> l >> r;
    cout << find(l, r) << endl;
  }
  return 0;
}
