#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long l, r;
    cin >> l >> r;
    for (long long i = 0; i <= 63; i++) {
      if ((l & (1LL << i)) == 0) {
        if ((l | (1LL << i)) > r) {
          break;
        }
        l |= (1LL << i);
      }
    }
    cout << l << '\n';
  }
  return 0;
}
