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