#include <bits/stdc++.h>
using namespace std;
long long n, l, r;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> l >> r;
    long long ans = 0;
    if (l == r)
      cout << l << "\n";
    else
      while (1) {
        long long u = l, v = r + 1;
        while ((u & -u) != u) u -= u & -u;
        ;
        while ((v & -v) != v) v -= v & -v;
        ;
        if (u != v) {
          cout << (v + ans - 1) << "\n";
          break;
        } else
          ans += u, l -= u, r -= u;
      }
  }
  return 0;
}
