#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  for (int z = 0; z < n; z++) {
    long long a, b, c;
    cin >> a >> b;
    while ((c = a | a + 1) <= b) a = (a | a + 1);
    cout << a << endl;
  }
  return 0;
}
