#include <bits/stdc++.h>
using namespace std;
unsigned long long int nr, n2, n, l, r, i, k, v[70], f[70], j, ok, sol;
int main() {
  cin >> n;
  n2 = 1;
  nr = 1;
  for (i = 1; i <= 63; i++) {
    k++;
    v[k] = nr;
    f[k] = n2;
    n2 *= 2;
    nr += n2;
  }
  for (i = 1; i <= n; i++) {
    cin >> l >> r;
    j = 1;
    while (r >= v[j]) j++;
    j--;
    if (l <= v[j]) {
      cout << v[j] << "\n";
    } else {
      j++;
      ok = 0;
      sol = v[j];
      while (sol > r && ok == 0) {
        for (k = j; k >= 1 && ok == 0; k--) {
          if (sol - f[k] >= l) {
            sol -= f[k];
            if (sol <= r) ok = 1;
          }
        }
        if (ok = 1) cout << sol << "\n";
      }
    }
  }
  return 0;
}
