#include <bits/stdc++.h>
using namespace std;
long long power(long long n) {
  long long res = 1;
  long long x = 2;
  while (n > 0) {
    if (n % 2) res *= x;
    x *= x;
    n >>= 1;
  }
  return res;
}
long long n, l, r, p[61];
int main() {
  cin >> n;
  for (long i = 0; i <= 60; i++) {
    p[i] = power(i);
  }
  for (long i = 0; i <= n - 1; i++) {
    cin >> l >> r;
    if (l == r)
      cout << l << endl;
    else {
      long long k = 0;
      while (p[k + 1] - 1 <= r) k++;
      long long res = p[k];
      if (res - 1 >= l)
        cout << res - 1 << endl;
      else {
        long long tmp;
        while (true) {
          k--;
          if (res + p[k] - 1 <= r) res += p[k];
          if (res - 1 >= l) {
            cout << res - 1 << endl;
            break;
          }
        }
      }
    }
  }
}
