#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  long long l, r;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> l >> r;
    long long ans = (long long)l;
    long long mask = 0LL;
    for (int i = 0; i < 64; i++) {
      mask <<= 1LL;
      mask += 1LL;
      long long temp = (long long)l;
      temp |= (long long)mask;
      if (temp <= r)
        ans = temp;
      else
        break;
    }
    cout << ans << endl;
  }
  return 0;
}
