#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  long long int a, b;
  cin >> n;
  while (n--) {
    cin >> a >> b;
    while ((a | (a + 1)) <= b) {
      a = a | (a + 1);
    }
    cout << a << endl;
  }
  return 0;
}
