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