#include <bits/stdc++.h>
using namespace std;
int arr[55];
long long int power[100];
int poper(long long int x) {
  int counter = 0;
  while (x) {
    x /= 2;
    counter++;
  }
  return counter;
}
int setcount(long long int x) {
  int counter = 0;
  while (x) {
    x &= (x - 1);
    counter++;
  }
  return counter;
}
int main() {
  power[0] = 1;
  for (int i = 1; i < 100; i++) {
    power[i] = 2 * power[i - 1];
  }
  long long int n;
  long long int l, r, temp;
  cin >> n;
  while (n--) {
    cin >> l >> r;
    long long int ans = 0;
    while (1) {
      int x = poper(l);
      int y = poper(r);
      if (l == r) {
        cout << ans + l << endl;
        break;
      } else if (x != y) {
        if (setcount(power[y - 1] - 1) < setcount(r)) {
          cout << ans + r << endl;
        } else {
          cout << ans + power[y - 1] - 1 << endl;
        }
        break;
      } else {
        l = l - power[y - 1];
        r = r - power[y - 1];
        ans = ans + power[y - 1];
      }
    }
  }
}
