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