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