#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long l, r, res, t;
  for (int i = 0; i < n; i++) {
    cin >> l >> r;
    res = l;
    for (int i = 0; i <= 60; i++) {
      t = res | ((long long)1 << i);
      if (t > r) break;
      res = t;
    }
    cout << res << endl;
  }
  return 0;
}
