#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int tc;
  cin >> tc;
  while (tc--) {
    long long l, r;
    cin >> l >> r;
    long long i = 1;
    while ((l | i) <= r) {
      l |= i;
      i <<= 1;
    }
    cout << l << '\n';
  }
}
