#include <bits/stdc++.h>
int main() {
  int tcase;
  for (scanf("%d", &tcase); tcase--;) {
    long long l, r;
    scanf("%lld%lld", &l, &r);
    if (l == r) {
      printf("%lld\n", r);
      continue;
    }
    int p = 63 - __builtin_clzll(l ^ r);
    long long temp = 0;
    for (int i = 63; i > p; --i)
      if (l >> i & 1) temp |= 1LL << i;
    long long a = (1LL << p) - 1, b = (1LL << (p + 1)) - 1;
    a |= temp, b |= temp;
    if (l <= b && b <= r) a = b;
    printf("%lld\n", a);
  }
  return 0;
}
