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