#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long l, r, x;
    cin >> l >> r;
    int k = 0;
    x = (r + 1) ^ l;
    while (x) {
      x >>= 1;
      k++;
    }
    x = 1;
    cout << (l | ((x << (k - 1)) - 1)) << endl;
  }
}
