#include <bits/stdc++.h>
using namespace std;
long long next(long long a) {
  long long i = 1LL;
  while (a & i) i <<= 1LL;
  return a + i;
}
int main() {
  int t;
  long long ans, l, r;
  scanf("%d", &t);
  while (t--) {
    scanf("%I64d%I64d", &l, &r);
    while (l <= r) {
      ans = l;
      l = next(l);
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
