#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t;
  cin >> t;
  while (t--) {
    long long l, r, ans;
    cin >> l >> r;
    if (l == r) {
      cout << l << endl;
      continue;
    }
    int cnt1 = 0, cnt2 = 0;
    long long left = l, right = r;
    while (left) {
      cnt1++;
      left /= 2;
    }
    while (right) {
      cnt2++;
      right /= 2;
    }
    if (r == pow(2, cnt2) - 1)
      cout << r << endl;
    else if (cnt1 != cnt2) {
      ans = (pow(2, cnt2 - 1));
      cout << ans - 1 << endl;
    } else {
      int chk = 1;
      vector<int> v;
      int cnt = 0;
      left = l;
      right = r;
      while (right) {
        if (left != 0 && (left % 2) == 0)
          v.push_back(cnt);
        else if (left == 0)
          v.push_back(cnt);
        cnt++;
        left /= 2;
        right /= 2;
      }
      long long num = l, ans2;
      int j = 0;
      while (num < r && v.size() != j) {
        num += (pow(2, v[j++]));
        if (num <= r) {
          ans = num;
          chk = 0;
        }
      }
      if (chk)
        cout << l << endl;
      else
        cout << ans << endl;
    }
  }
  return 0;
}
