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