#include <bits/stdc++.h>
using namespace std;
long long n, m, k, x, a[1000008], b[1000008];
long long B, S, C, nB, nS, nC, pB, pS, pC;
long long l, r;
long long ans(0);
int main() {
  scanf("%lld", &n);
  while (n--) {
    scanf("%lld %lld", &l, &r);
    ans = l;
    for (int i = 0; i < 61; ++i)
      if ((ans | (1ll << i)) <= r) ans |= (1ll << i);
    printf("%lld\n", ans);
  }
  return 0;
}
