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