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