#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    unsigned long long x, l, r;
    int j = 0;
    cin >> l >> r;
    x = l;
    while (1) {
      if (j >= 64) break;
      unsigned long long tmp = x | ((unsigned long long)(1LL << j));
      if (tmp <= r)
        x = tmp;
      else
        break;
      j++;
    }
    cout << x << endl;
  }
  return 0;
}
