#include <bits/stdc++.h>
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    long long l, r, tmp, p = 1;
    scanf("%I64d %I64d", &l, &r);
    for (long long i = 0; i < 63; i++) {
      long long tmp = l | p;
      if (tmp > r) break;
      l = tmp;
      p <<= 1;
    }
    printf("%I64d\n", l);
  }
}
