#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    long long l, r;
    cin >> l >> r;
    long long ans = (1LL << 60) - 1;
    for (int i = 59; i >= 0; i--) {
      if (ans >= l && ans <= r) break;
      if ((ans ^ (1LL << i)) < l) continue;
      ans ^= (1LL << i);
    }
    cout << ans << endl;
  }
  return 0;
}
