#include <bits/stdc++.h>
using namespace std;
long long int det(long long int a, long long int b, int bit) {
  if (!bit) {
    if (a & 1) return a;
    if (b & 1) return b;
    return a;
  }
  if (a & (1ll << bit)) return det(a, b, bit - 1);
  if (!(b & (1ll << bit))) return det(a, b, bit - 1);
  if ((b & ((1ll << (bit + 1)) - 1)) == ((1ll << (bit + 1)) - 1)) return b;
  return ((a & (~((1ll << bit) - 1))) | ((1ll << bit) - 1));
}
int main() {
  int n = 0;
  cin >> n;
  long long int a = 0, b = 0;
  while (n--) {
    cin >> a >> b;
    cout << det(a, b, 60) << '\n';
  }
  return 0;
}
