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