#include <bits/stdc++.h>
using namespace std;
int t;
long long l, r;
inline void solve() {
  cin >> t;
  while (t--) {
    cin >> l >> r;
    long long ans = l;
    for (int i = 0; i <= 62; ++i) {
      if (ans + (1ll << i) <= r && (ans & (1ll << i)) == 0) {
        ans += (1ll << i);
      }
    }
    cout << ans << endl;
  }
}
int main() {
  solve();
  return 0;
}
