#include <bits/stdc++.h>
int main() {
  long long n, l, r, i, j, a;
  std::cin >> n;
  for (i = 1; i <= n; i++) {
    std::cin >> l >> r;
    for (j = l; j <= r; j += ~j & -~j) a = j;
    std::cout << a << "\n";
  }
}
