#include <bits/stdc++.h>
using namespace std;
long long solve(long long l, long long r) {
  long long x = log2(r);
  x = pow(2, x);
  if (l == r) return l;
  if (x <= l)
    return x + solve(l - x, r - x);
  else if (x * 2 - 1 <= r)
    return 2 * x - 1;
  else
    return x - 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int q;
  cin >> q;
  while (q-- > 0) {
    long long l, r;
    cin >> l >> r;
    cout << solve(l, r) << '\n';
  }
  return 0;
}
