#include <bits/stdc++.h>
using namespace std;
int n;
long long l, r;
int main() {
  std::ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  while (n--) {
    cin >> l >> r;
    while ((l | (l + 1)) <= r) l = (l | (l + 1));
    cout << l << "\n";
  }
  return 0;
}
