#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    unsigned long long i, j, n, m, ans = 0, temp = 0, l, r, f = 0;
    cin >> l >> r;
    if (l == r && l == 0)
      cout << "0\n";
    else {
      for (i = 1; i <= 1000000000000000000; i *= 2) {
        temp += i;
        if (temp > r)
          break;
        else
          ans++;
        if (temp >= l && temp <= r) f = 1;
      }
      if (f == 0) {
        ans++;
        while (temp > r) {
          if (temp - (i >> 1) >= l) temp -= (i >> 1);
          i >>= 1;
        }
      } else if (temp > r)
        temp -= i;
      cout << temp << "\n";
    }
  }
  return 0;
}
