#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    long long l, r;
    cin >> l >> r;
    for (int i = 0; i <= 60; i++) {
      if (l + (1ll << i) <= r && ((l >> i) & 1) == 0) {
        l |= (1ll << i);
      }
    }
    cout << l << endl;
  }
}
