#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e7 + 100;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  while (n--) {
    long long l, r;
    cin >> l >> r;
    long long ans = l;
    for (long long i = 0; i < 63; i++) {
      if (!((1LL << i) & ans)) {
        if ((ans | (1LL << i)) <= r) ans |= (1LL << i);
      }
    }
    cout << ans << "\n";
  }
}
