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