#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long long int n, l, r, num, d, ans, t;
  cin >> n;
  for (long long int i = 0; i < n; i++) {
    cin >> l >> r;
    ans = l;
    num = l;
    d = __builtin_popcount(l);
    for (int i = 0; i <= 62; i++) {
      num = num | (1ll << i);
      if (num >= l && num <= r) {
        t = __builtin_popcount(num);
        if (t > d) {
          ans = num;
        }
      } else
        break;
    }
    cout << ans << endl;
  }
  return 0;
}
