#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long T;
  cin >> T;
  while (T--) {
    long long l, r;
    cin >> l >> r;
    for (long long i = 1; (l | i) <= r; i <<= 1) l |= i;
    printf("%lld%c", l, "\0\n"[T != 0]);
  }
  return 0;
}
