#include <bits/stdc++.h>
using namespace std;
long long n, l, r;
inline long long query(long long l, long long r) {
  for (long long i = 62; i >= 1; i--) {
    if ((1ll << i) - 1 >= l && (1ll << i) - 1 <= r) return (1ll << i) - 1;
  }
  for (long long i = 62; i >= 0; i--)
    if (((1ll << i) & l) > 0 && ((1ll << i) & r) > 0)
      return (1ll << i) + query(l - (1ll << i), r - (1ll << i));
}
int main() {
  scanf("%lld", &n);
  while (n--) {
    scanf("%lld%lld", &l, &r);
    if (l > r) {
      long long t = l;
      l = r;
      r = t;
    }
    if (l == r) {
      printf("%lld\n", l);
      continue;
    }
    printf("%lld\n", query(l, r));
  }
  return 0;
}
