#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    long long l, r;
    cin >> l >> r;
    for (int j = 0; (1ll << j) <= r; j++)
      if ((l | (1ll << j)) <= r) l |= (1ll << j);
    cout << l << endl;
  }
}
