#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  long long l, r;
  while (t--) {
    cin >> l >> r;
    for (int i = 0; i <= 61; ++i) {
      if ((l & (1LL << i)) == 0) {
        if (l + (1LL << i) <= r)
          l += (1LL << i);
        else
          break;
      }
    }
    cout << l << "\n";
  }
  return 0;
}
