#include <bits/stdc++.h>
using namespace std;
const long long one = 1;
int main() {
  int N, i;
  long long answer, l, r, v;
  cin >> N;
  while (N--) {
    cin >> l >> r;
    v = answer = l;
    for (i = 0; i < 63; i++) {
      v |= one << i;
      if (v <= r) answer = v;
    }
    cout << answer << "\n";
  }
  return 0;
}
