#include <bits/stdc++.h>
using namespace std;
int c = 0;
long long int calc(long long int a, long long int b) {
  long long int r = 0;
  for (int i = 0; i < 64 && (1LL << i <= b + 1); i++) r = 1LL << i;
  if (r > a) return max(r - 1, 0LL);
  return r + calc(a - r, b - r);
}
int main() {
  long long int n, l, r;
  cin >> n;
  for (int t = 0; t < n; t++) {
    cin >> l >> r;
    cout << calc(l, r) << endl;
  }
  return 0;
}
