#include <bits/stdc++.h>
using namespace std;
int num1[100], num2[100];
int main() {
  ios_base::sync_with_stdio(false);
  long long int l, r, d1, d2, tl, tr, n;
  cin >> n;
  while (n--) {
    cin >> l >> r;
    d1 = 0;
    tl = l;
    memset(num1, 0, sizeof(num1));
    memset(num2, 0, sizeof(num2));
    while (l) {
      num1[d1++] = l % 2;
      l /= 2;
    }
    d2 = 0;
    tr = r;
    while (r) {
      num2[d2++] = r % 2;
      r /= 2;
    }
    int i = d2 - 1;
    long long int ans = 0;
    long long int tmp = 0;
    while (num1[i] == num2[i] && i >= 0) {
      if (num1[i] == 1) {
        ans |= (1LL << i);
        tmp |= (1LL << i);
      }
      i--;
    }
    if (i >= 0) tmp |= (1LL << i);
    i--;
    while (i >= 0) {
      ans |= (1LL << i);
      tmp |= (1LL << i);
      i--;
    }
    if (tmp == tr) ans = tmp;
    cout << ans << endl;
  }
  return 0;
}
