#include <bits/stdc++.h>
const long long mod = 1e8;
using namespace std;
bool in(int x, int l, int r) { return l <= x && x <= r; }
void solve() {
  long long l, r;
  cin >> l >> r;
  vector<long long> v;
  long long p = -1;
  for (int i = 61; i >= 0; i--) {
    unsigned long long mask = 1ull << i;
    if (mask & r) {
      v.push_back(i);
      if (mask & l) {
        continue;
      } else {
        p = i;
        break;
      }
    }
  }
  long long ans = 0;
  if (v.size() == 0) {
    cout << l << "\n";
    return;
  }
  int q = 0;
  for (int i = p - 1; i >= 0; i--) {
    unsigned long long mak = 1ull << i;
    if (mak & r) q++;
  }
  if (q == p) {
    cout << r << "\n";
    return;
  }
  for (int i = 0; i < v.size(); i++) {
    if (v[i] != p) ans += pow(2, v[i]);
  }
  for (int i = p - 1; i >= 0; i--) ans += pow(2, i);
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
