#include <bits/stdc++.h>
long double eps = 1e-8;
using namespace std;
signed main() {
  long long t, l, r;
  cin >> t;
  while (t--) {
    cin >> l >> r;
    for (long long i = 0; i < 60; ++i) {
      if ((l | ((long long)1 << i)) <= r) l |= ((long long)1 << i);
    }
    cout << l << '\n';
  }
  return 0;
}
