#include <bits/stdc++.h>
using namespace std;
template <class T>
using maxheap = priority_queue<T, vector<T>, less<T>>;
template <class T>
using minheap = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
void setmax(T& a, T b) {
  a = max(a, b);
};
template <typename T>
void setmin(T& a, T b) {
  a = min(a, b);
};
template <typename T>
bool in(T lo, T v, T hi) {
  return lo <= v && v <= hi;
};
template <typename T>
ostream& operator<<(ostream& out, vector<T>& v) {
  out << "[";
  int n = v.size();
  for (int i = 0; i < n; i++) out << v[i] << (i + 1 < n ? ", " : "");
  out << "]";
  return out;
}
struct timestamp {
  string algo;
  long double A, B;
  timestamp(string _algo) {
    algo = _algo;
    A = B = clock();
  }
  void print() {
    long double B_ = clock();
    long double section = (B_ - B) / CLOCKS_PER_SEC;
    long double cumulative = (B_ - A) / CLOCKS_PER_SEC;
    cout << algo << " profile(seconds): section: " << section
         << " cumulative: " << cumulative << '\n'
         << flush;
    B = B_;
  }
};
template <long long MOD>
struct ModInt {
  long long x = 0;
  ModInt() { x = 0; }
  ModInt(long long _x) {
    x = _x;
    if (x >= MOD || x <= -MOD) x %= MOD;
    if (x < 0) x += MOD;
  }
  friend ModInt operator+(ModInt a, ModInt b) { return ModInt(a.x + b.x); }
  friend ModInt operator-(ModInt a, ModInt b) { return ModInt(a.x - b.x); }
  friend ModInt operator*(ModInt a, ModInt b) { return ModInt(a.x * b.x); }
  friend ModInt operator/(ModInt a, ModInt b) { return a * inv(b); }
  friend ModInt operator+=(ModInt& a, ModInt b) { return a = a + b; }
  friend ModInt power(ModInt a, long long b) {
    if (b == 0) return 1;
    ModInt c = power(a, b / 2);
    return c * c * ((b & 1) ? a : 1);
  }
  friend ModInt inv(ModInt a) { return power(a, MOD - 2); }
  friend ostream& operator<<(ostream& os, const ModInt& a) {
    os << a.x;
    return os;
  }
  friend istream& operator>>(istream& is, ModInt& a) {
    long long y;
    is >> y;
    a = ModInt(y);
    return is;
  }
};
using mint = ModInt<998244353>;
using vm = vector<mint>;
using vvm = vector<vm>;
const int N = 3e5 + 10;
long long X[N];
void precalc() {
  for (int i = 1; i < N; i++) X[i] = X[i - 1] ^ i;
}
struct Solution {
  void solve() {
    long long m, x;
    cin >> m >> x;
    long long y = X[m - 1];
    if (y == x) {
      cout << m << '\n';
    } else if ((y ^ x) == m) {
      cout << (m + 2) << '\n';
    } else {
      cout << (m + 1) << '\n';
    }
  }
};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  precalc();
  int t = 1;
  cin >> t;
  while (t--) {
    Solution second;
    second.solve();
  }
  return 0;
}

### Prompt

Construct a cpp code solution to the problem outlined:

Alice gave Bob two integers a and b (a > 0 and b ≥ 0). Being a curious boy, Bob wrote down an array of non-negative integers with \operatorname{MEX} value of all elements equal to a and \operatorname{XOR} value of all elements equal to b.

What is the shortest possible length of the array Bob wrote?

Recall that the \operatorname{MEX} (Minimum EXcluded) of an array is the minimum non-negative integer that does not belong to the array and the \operatorname{XOR} of an array is the [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of all the elements of the array.

Input

The input consists of multiple test cases. The first line contains an integer t (1 ≤ t ≤ 5 ⋅ 10^4) — the number of test cases. The description of the test cases follows.

The only line of each test case contains two integers a and b (1 ≤ a ≤ 3 ⋅ 10^5; 0 ≤ b ≤ 3 ⋅ 10^5) — the \operatorname{MEX} and \operatorname{XOR} of the array, respectively.

Output

For each test case, output one (positive) integer — the length of the shortest array with \operatorname{MEX} a and \operatorname{XOR} b. We can show that such an array always exists.

Example

Input


5
1 1
2 1
2 0
1 10000
2 10000


Output


3
2
3
2
3

Note

In the first test case, one of the shortest arrays with \operatorname{MEX} 1 and \operatorname{XOR} 1 is [0, 2020, 2021].

In the second test case, one of the shortest arrays with \operatorname{MEX} 2 and \operatorname{XOR} 1 is [0, 1].

It can be shown that these arrays are the shortest arrays possible.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
using maxheap = priority_queue<T, vector<T>, less<T>>;
template <class T>
using minheap = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
void setmax(T& a, T b) {
  a = max(a, b);
};
template <typename T>
void setmin(T& a, T b) {
  a = min(a, b);
};
template <typename T>
bool in(T lo, T v, T hi) {
  return lo <= v && v <= hi;
};
template <typename T>
ostream& operator<<(ostream& out, vector<T>& v) {
  out << "[";
  int n = v.size();
  for (int i = 0; i < n; i++) out << v[i] << (i + 1 < n ? ", " : "");
  out << "]";
  return out;
}
struct timestamp {
  string algo;
  long double A, B;
  timestamp(string _algo) {
    algo = _algo;
    A = B = clock();
  }
  void print() {
    long double B_ = clock();
    long double section = (B_ - B) / CLOCKS_PER_SEC;
    long double cumulative = (B_ - A) / CLOCKS_PER_SEC;
    cout << algo << " profile(seconds): section: " << section
         << " cumulative: " << cumulative << '\n'
         << flush;
    B = B_;
  }
};
template <long long MOD>
struct ModInt {
  long long x = 0;
  ModInt() { x = 0; }
  ModInt(long long _x) {
    x = _x;
    if (x >= MOD || x <= -MOD) x %= MOD;
    if (x < 0) x += MOD;
  }
  friend ModInt operator+(ModInt a, ModInt b) { return ModInt(a.x + b.x); }
  friend ModInt operator-(ModInt a, ModInt b) { return ModInt(a.x - b.x); }
  friend ModInt operator*(ModInt a, ModInt b) { return ModInt(a.x * b.x); }
  friend ModInt operator/(ModInt a, ModInt b) { return a * inv(b); }
  friend ModInt operator+=(ModInt& a, ModInt b) { return a = a + b; }
  friend ModInt power(ModInt a, long long b) {
    if (b == 0) return 1;
    ModInt c = power(a, b / 2);
    return c * c * ((b & 1) ? a : 1);
  }
  friend ModInt inv(ModInt a) { return power(a, MOD - 2); }
  friend ostream& operator<<(ostream& os, const ModInt& a) {
    os << a.x;
    return os;
  }
  friend istream& operator>>(istream& is, ModInt& a) {
    long long y;
    is >> y;
    a = ModInt(y);
    return is;
  }
};
using mint = ModInt<998244353>;
using vm = vector<mint>;
using vvm = vector<vm>;
const int N = 3e5 + 10;
long long X[N];
void precalc() {
  for (int i = 1; i < N; i++) X[i] = X[i - 1] ^ i;
}
struct Solution {
  void solve() {
    long long m, x;
    cin >> m >> x;
    long long y = X[m - 1];
    if (y == x) {
      cout << m << '\n';
    } else if ((y ^ x) == m) {
      cout << (m + 2) << '\n';
    } else {
      cout << (m + 1) << '\n';
    }
  }
};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  precalc();
  int t = 1;
  cin >> t;
  while (t--) {
    Solution second;
    second.solve();
  }
  return 0;
}

```