#include <bits/stdc++.h>
using namespace std;
void d() { cerr << '\n'; }
template <typename H, typename... T>
void d(H h, T... t) {
  cerr << ' ' << h;
  d(t...);
}
void absinthe() {
  long long l, r, z = 0;
  cin >> l >> r;
  if (__builtin_popcountll(r) == (64 - __builtin_clzll(r))) {
    cout << r << '\n';
    return;
  }
  for (long long i = (63 - __builtin_clzll(r)); i >= 0; i--) {
    long long chk = (1LL << i);
    ;
    if ((r & chk) == (l & chk)) {
      if (l & chk) z += chk;
    } else {
      if (z + (chk << 1LL) - 1LL <= r)
        z += (chk << 1LL) - 1LL;
      else
        z += chk - 1LL;
      break;
    }
  }
  cout << z << '\n';
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int __t = 1, __c;
  cin >> __t;
  for (__c = 1; __c <= __t; __c++) {
    absinthe();
  }
}
