#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  int n, i;
  cin >> n;
  while (n--) {
    long long l, r, a;
    cin >> l >> r;
    a = l;
    long long t = 0;
    while (a <= r) {
      t = (~a & ~(~a - 1));
      a = a + t;
    }
    a = a - t;
    cout << a << endl;
  }
  return 0;
}
