#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
  cin >> n;
  while (n--) {
    long long l, r;
    cin >> l >> r;
    for (int mask = 0; mask < 65; ++mask) {
      if ((l & (1ll << mask)) == 0) {
        if ((l | (1ll << mask)) > r) break;
        l |= (1ll << mask);
      }
    }
    cout << l << '\n';
  }
  return 0;
}
