#include <bits/stdc++.h>
using namespace std;
void ac() {
  long long l, r;
  cin >> l >> r;
  long long num = 1;
  while (l + num <= r) {
    if ((l | num) != l) l += num;
    num <<= 1;
  }
  cout << l << endl;
}
int main() {
  int n;
  cin >> n;
  while (n--) {
    ac();
  }
}
