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