#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  while (n--) {
    long long a, b;
    cin >> a >> b;
    long long ans = 0;
    for (int bit = (int)(60) - 1; bit >= 0; --bit) {
      if (!(a & (1ll << bit)) && (b & (1ll << bit))) {
        ans |= (1ll << bit) - 1;
        break;
      }
      ans |= b & (1ll << bit);
    }
    if (__builtin_popcountll(b) > __builtin_popcountll(a)) swap(a, b);
    if (__builtin_popcountll(a) > __builtin_popcountll(ans)) swap(ans, a);
    cout << ans << '\n';
  }
  return 0;
}
