#include <bits/stdc++.h>
using namespace std;
template <class T>
T sqr(T x) {
  return x * x;
}
int main() {
  long long i, j, l, r, x, n;
  scanf("%lld", &n);
  for (i = 1; i <= n; i++) {
    scanf("%lld%lld", &l, &r);
    x = l;
    for (j = 0; j <= 62; j++)
      if (!((1LL << j) & x) && (1LL << j) + x <= r) x += 1LL << j;
    printf("%lld\n", x);
  }
}
