#include <bits/stdc++.h>
using namespace std;
long long L, R, N, i;
int main() {
  cin >> N;
  while (N--) {
    cin >> L >> R;
    for (i = 0; i < 64; i++) {
      if (((((long long)1 << i) & L) == 0) && (L ^ ((long long)1 << i)) <= R) {
        L ^= (((long long)1) << i);
      }
      if ((L ^ ((long long)1 << i)) > R) break;
    }
    cout << L << endl;
  }
}
