#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long l, r;
    cin >> l >> r;
    long long p1 = log2(l);
    long long p = (long long)1 << p1;
    if (p <= 2) p = 0, p1 = 0;
    long long x = 1, ans = p;
    while (1) {
      long long p = (long long)1 << (p1);
      if (p - 1 <= r) {
        ans = p - 1;
        p1++;
      } else
        break;
    }
    if (ans >= l && ans <= r) {
      cout << ans << endl;
    } else {
      while (ans < l) {
        long long q = r - ans;
        long long q1 = (long long)log2(q);
        ans = ans + ((long long)1 << q1);
      }
      cout << ans << endl;
    }
  }
}
