#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long a, b, k;
    cin >> a >> b;
    k = a;
    for (int i = 0; i < 64; i++) {
      a |= 1ll << i;
      if (a > b)
        break;
      else if (a > k)
        k = a;
    }
    cout << k << "\n";
  }
}
