#include <bits/stdc++.h>
int main() {
  long long T, l, r;
  scanf("%lld", &T);
  while (T--) {
    scanf("%lld%lld", &l, &r);
    while ((l | (l + 1)) <= r) l |= l + 1;
    printf("%lld\n", l);
  }
  return 0;
}
