#include <bits/stdc++.h>
using namespace std;
long long ans(long long l, long long r) {
  if (l == r) return l;
  int di = 62;
  while (true) {
    if ((1ll << di) <= r)
      break;
    else
      di--;
  }
  long long curP = 1ll << di;
  if (l >= curP)
    return curP + ans(l - curP, r - curP);
  else if (r == (curP * 2 - 1))
    return curP * 2 - 1;
  else
    return curP - 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = int(0); i < int(n); i++) {
    long long l, r;
    cin >> l >> r;
    cout << ans(l, r) << endl;
  }
}
