#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, N, bitl, bitr;
  long long l, r;
  scanf("%d", &N);
  while (N--) {
    scanf("%lld%lld", &l, &r);
    bitl = bitr = 0;
    if (l == r) {
      printf("%lld\n", l);
      continue;
    }
    while ((1LL << bitl) <= l) ++bitl;
    while ((1LL << bitr) <= r) ++bitr;
    --bitl;
    --bitr;
    if (bitl < bitr) {
      if ((1LL << (bitr + 1)) - 1 == r)
        printf("%lld\n", r);
      else
        printf("%lld\n", (1LL << bitr) - 1);
      continue;
    }
    for (i = bitr; i >= 0; --i) {
      if (((l >> i) % 2) != ((r >> i) % 2)) break;
    }
    if ((((1LL << (i + 1)) - 1) & r) == (1LL << (i + 1)) - 1)
      printf("%lld\n", r);
    else {
      r |= (1LL << i) - 1;
      r &= ~(1LL << i);
      printf("%lld\n", r);
    }
  }
  return 0;
}
