#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 5, nax = 1e6 + 5;
long long pot[105];
int main() {
  ios_base ::sync_with_stdio(false);
  pot[0] = 1;
  for (int i = 1, _n = (100); i <= _n; ++i) pot[i] = pot[i - 1] * 2LL;
  int z;
  cin >> z;
  while (z--) {
    long long low, high;
    cin >> low >> high;
    if (low == high)
      cout << low << "\n";
    else {
      for (int k = 60; k >= 0; --k)
        if ((high & pot[k]) && !(low & pot[k])) {
          low = (low >> k);
          low++;
          low = (low << k);
          low--;
          long long res = low;
          res += (1LL << k);
          if (res == high)
            cout << res << "\n";
          else
            cout << low << "\n";
          k = -1;
        }
    }
  }
  return 0;
}
