#include <bits/stdc++.h>
using namespace std;
long long ite, a, b;
bool ok(long long n) { return ((a <= n) && (n <= b)); }
long long one = 1;
int main() {
  cin >> ite;
  while (ite--) {
    cin >> a >> b;
    long long res = a;
    for (int i = 0; 1; i++) {
      if (ok(res | (one << i)))
        res = res | (one << i);
      else
        break;
    }
    cout << res << endl;
  }
  return 0;
}
