#include <bits/stdc++.h>
int main() {
  long t;
  scanf("%ld\n", &t);
  while (t--) {
    long long left, right;
    scanf("%lld %lld\n", &left, &right);
    long long add = 1;
    for (int p = 0; p < 63; p++) {
      if ((left | add) > right) {
        break;
      }
      left |= add;
      add <<= 1;
    }
    printf("%lld\n", left);
  }
  return 0;
}
