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