#include <bits/stdc++.h>
using namespace std;
long long popcount(long long l, long long r) {
  long long ans = 0;
  while (1) {
    if (l == r) {
      ans += l;
      break;
    } else {
      long long temp1 = log2(r);
      temp1 = pow(2, temp1);
      long long temp3 = temp1 * 2 - 1;
      if (temp3 == r) {
        ans += temp3;
        break;
      }
      long long temp2 = temp1 - 1;
      if (temp2 >= l) {
        ans += temp2;
        break;
      } else {
        ans += temp1;
        l = l ^ temp1;
        r = r ^ temp1;
      }
    }
  }
  return ans;
}
int main() {
  int n;
  scanf("%d", &n);
  while (n--) {
    long long l, r;
    cin >> l;
    cin >> r;
    long long ans = popcount(l, r);
    cout << ans << endl;
  }
}
