#include <bits/stdc++.h>
using namespace std;
int main() {
  long long L, R;
  int n;
  cin >> n;
  while (n--) {
    cin >> L >> R;
    for (long long k = 0; k <= 60; ++k) {
      if ((1LL << k) & (L)) {
        continue;
      } else {
        if ((1LL << k) + L <= R) {
          L += (1LL << k);
        } else {
          break;
        }
      }
    }
    cout << L << "\n";
  }
  return 0;
}
