#include <bits/stdc++.h>
using namespace std;
long long int n, l, r, ans, p[64];
int main() {
  cin >> n;
  p[0] = 1;
  for (int i = 1; i < 63; i++) p[i] = p[i - 1] * 2;
  for (int i = 0; i < n; i++) {
    ans = 0;
    cin >> l >> r;
    for (int i = 62; i >= 0; i--) {
      if ((r & p[i]) && ((l & p[i]) == 0)) {
        if (r == p[i + 1] - 1) {
          ans += p[i + 1] - 1;
        } else
          ans += p[i] - 1;
        break;
      } else if ((r & p[i]) && (l & (p[i]))) {
        ans += p[i];
      }
      if (r & p[i]) r ^= p[i];
      if (l & p[i]) l ^= p[i];
    }
    cout << ans << endl;
  }
}
