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