#include <bits/stdc++.h>
using namespace std;
unsigned long long sol, x, y;
int n;
int main() {
  cin >> n;
  for (; n > 0; --n) {
    cin >> x >> y;
    sol = 0;
    sol = x;
    int k = 0;
    bool t = 1;
    for (; k < 64 && t; ++k)
      if (!(sol & (1LL << k))) {
        if (sol + (1LL << k) <= y)
          sol += (1LL << k);
        else
          t = 0;
      }
    cout << sol << '\n';
  }
  return 0;
}
