#include <bits/stdc++.h>
using namespace std;
long long G(long long a, long long b) {
  if (b == 0) return a;
  return G(b, a % b);
}
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  long long l, r, k;
  for (int i = 0; i < n; i++) {
    cin >> l >> r;
    if (r == l) {
      cout << l << endl;
      continue;
    }
    for (long long j = 60; j >= 0; j--) {
      if ((1ll << j & r) && ((1ll << j & l) == 0)) {
        r -= (1ll << j);
        bool f = 1;
        for (long long k = j - 1; k >= 0; k--) {
          if ((r & (1ll << k)) == 0) f = 0;
          r |= (1ll << k);
        }
        if (f) r += (1ll << j);
        cout << r << endl;
        break;
      }
    }
  }
}
