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