#include <bits/stdc++.h>
using namespace std;
int main() {
  int h[64];
  long long n, l, r;
  cin >> n;
  for (int u = 0; u < n; ++u) {
    for (int i = 0; i < 64; ++i) {
      h[i] = 0;
    }
    cin >> l >> r;
    for (int i = 0; i < 64; ++i) {
      h[i] = (l >> i) & 0x1;
    }
    for (long long i = 0; i < 64; ++i) {
      if (h[i] != 0) continue;
      if (l + (1LL << i) <= r)
        l += 1LL << i;
      else
        break;
    }
    cout << l << endl;
  }
  return 0;
}
