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