#include <bits/stdc++.h>
using namespace std;
using namespace std;
const double pi = acos(-1.0);
long long solve(long long a, long long b) {
  if (a == b) return a;
  long long msb = (int)log2(b);
  long long bit = 1LL << msb;
  if (a >= bit) {
    return bit + solve(a - bit, b - bit);
  } else if (2 * bit - 1 <= b)
    return 2 * bit - 1;
  else
    return bit - 1;
  return -1;
}
int main() {
  int n;
  cin >> n;
  for (int(kase) = (1); (kase) <= (n); ++(kase)) {
    long long a, b;
    cin >> a >> b;
    cout << solve(a, b) << '\n';
  }
}
