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