#include <bits/stdc++.h>
template <typename T>
T in() {
  char ch;
  T n = 0;
  bool ng = false;
  while (1) {
    ch = getchar();
    if (ch == '-') {
      ng = true;
      ch = getchar();
      break;
    }
    if (ch >= '0' && ch <= '9') break;
  }
  while (1) {
    n = n * 10 + (ch - '0');
    ch = getchar();
    if (ch < '0' || ch > '9') break;
  }
  return (ng ? -n : n);
}
using namespace std;
long long int check(long long int n, long long int bit) {
  return (n & (1LL << bit));
}
int main() {
  int t;
  cin >> t;
  for (int cs = 0; cs < t; cs++) {
    long long int a, b;
    cin >> a >> b;
    long long int ans = 0, f = 0;
    for (long long int i = 62; i >= 0; i--) {
      if (f) {
        ans += (1LL << i);
      } else {
        if (check(a, i) && check(b, i))
          ans += (1LL << i);
        else if (check(b, i) && !check(a, i))
          f = 1;
      }
    }
    if (__builtin_popcountll(b) > __builtin_popcountll(ans)) ans = b;
    cout << ans << endl;
  }
  return 0;
}
