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