#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long power(long long x, long long y, long long m) {
  if (y == 0) return 1;
  long long p = power(x, y / 2, m) % m;
  p = (p * p) % m;
  return (y % 2 == 0) ? p : (x * p) % m;
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long modInverse(long long a, long long m) {
  long long g = gcd(a, m);
  if (g != 1)
    cout << "Inverse doesn't exist";
  else {
    return power(a, m - 2, m);
  }
}
long long log_a_b(long long a, long long b) {
  return (a > b - 1) ? 1 + log_a_b(a / b, b) : 0;
}
int t;
vector<vector<long long> > graph;
vector<long long> tin, tout;
vector<bool> vis;
vector<vector<long long> > up;
void dfs(int v, int p, int l) {
  vis[v] = true;
  tin[v] = ++t;
  up[v][0] = p;
  for (int(i) = (1); (i) < (l + 1); (i)++) {
    up[v][i] = up[v][i - 1] < 0 ? -1 : up[up[v][i - 1]][i - 1];
  }
  for (int x : graph[v])
    if (!vis[x]) dfs(x, v, l);
  tout[v] = ++t;
}
bool isan(int u, int v) { return tin[u] <= tin[v] && tout[u] >= tout[v]; }
int lca(int u, int v, int l) {
  if (isan(u, v)) return u;
  if (isan(v, u)) return v;
  for (int(i) = (l); (i) >= (0); (i)--) {
    if (up[u][i] == -1) continue;
    if (!isan(up[u][i], v)) u = up[u][i];
  }
  return up[u][0];
}
bool sum(long long n, long long i, long long s, long long cnt,
         vector<long long> &a) {
  if (i >= n && cnt > 0) {
    if (s != 0)
      return 0;
    else
      return 1;
  }
  if (i >= n && cnt == 0) return 0;
  bool a1 = sum(n, i + 1, s, cnt, a);
  bool b = sum(n, i + 1, s - a[i], cnt + 1, a);
  bool c = sum(n, i + 1, s + a[i], cnt + 1, a);
  bool d = (a1 | b | c);
  return d;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(15);
  long long T;
  cin >> T;
  while (T--) {
    long long n, q, k, m, u, v, w, x;
    string s, t;
    cin >> n >> m;
    long long ans = 0;
    m++;
    vector<long long> a(31), b(31);
    for (int(i) = (0); (i) < (31); (i)++) {
      a[i] = n % 2;
      b[i] = m % 2;
      n /= 2;
      m /= 2;
    }
    reverse((a).begin(), (a).end());
    reverse((b).begin(), (b).end());
    for (int(i) = (0); (i) < (31); (i)++) {
      if (a[i] && !b[i]) break;
      if (!a[i] && b[i]) ans = ans | (1 << (30 - i));
    }
    cout << ans << "\n";
  }
  return 0;
}

### Prompt

Develop a solution in Cpp to the problem described below:

You are given two integers n and m. Find the \operatorname{MEX} of the sequence n ⊕ 0, n ⊕ 1, …, n ⊕ m. Here, ⊕ is the [bitwise XOR operator](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).

\operatorname{MEX} of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, \operatorname{MEX}(0, 1, 2, 4) = 3, and \operatorname{MEX}(1, 2021) = 0. 

Input

The first line contains a single integer t (1 ≤ t ≤ 30 000) — the number of test cases.

The first and only line of each test case contains two integers n and m (0 ≤ n, m ≤ 10^9).

Output

For each test case, print a single integer — the answer to the problem.

Example

Input


5
3 5
4 6
3 2
69 696
123456 654321


Output


4
3
0
640
530866

Note

In the first test case, the sequence is 3 ⊕ 0, 3 ⊕ 1, 3 ⊕ 2, 3 ⊕ 3, 3 ⊕ 4, 3 ⊕ 5, or 3, 2, 1, 0, 7, 6. The smallest non-negative integer which isn't present in the sequence i. e. the \operatorname{MEX} of the sequence is 4.

In the second test case, the sequence is 4 ⊕ 0, 4 ⊕ 1, 4 ⊕ 2, 4 ⊕ 3, 4 ⊕ 4, 4 ⊕ 5, 4 ⊕ 6, or 4, 5, 6, 7, 0, 1, 2. The smallest non-negative integer which isn't present in the sequence i. e. the \operatorname{MEX} of the sequence is 3.

In the third test case, the sequence is 3 ⊕ 0, 3 ⊕ 1, 3 ⊕ 2, or 3, 2, 1. The smallest non-negative integer which isn't present in the sequence i. e. the \operatorname{MEX} of the sequence is 0.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long power(long long x, long long y, long long m) {
  if (y == 0) return 1;
  long long p = power(x, y / 2, m) % m;
  p = (p * p) % m;
  return (y % 2 == 0) ? p : (x * p) % m;
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long modInverse(long long a, long long m) {
  long long g = gcd(a, m);
  if (g != 1)
    cout << "Inverse doesn't exist";
  else {
    return power(a, m - 2, m);
  }
}
long long log_a_b(long long a, long long b) {
  return (a > b - 1) ? 1 + log_a_b(a / b, b) : 0;
}
int t;
vector<vector<long long> > graph;
vector<long long> tin, tout;
vector<bool> vis;
vector<vector<long long> > up;
void dfs(int v, int p, int l) {
  vis[v] = true;
  tin[v] = ++t;
  up[v][0] = p;
  for (int(i) = (1); (i) < (l + 1); (i)++) {
    up[v][i] = up[v][i - 1] < 0 ? -1 : up[up[v][i - 1]][i - 1];
  }
  for (int x : graph[v])
    if (!vis[x]) dfs(x, v, l);
  tout[v] = ++t;
}
bool isan(int u, int v) { return tin[u] <= tin[v] && tout[u] >= tout[v]; }
int lca(int u, int v, int l) {
  if (isan(u, v)) return u;
  if (isan(v, u)) return v;
  for (int(i) = (l); (i) >= (0); (i)--) {
    if (up[u][i] == -1) continue;
    if (!isan(up[u][i], v)) u = up[u][i];
  }
  return up[u][0];
}
bool sum(long long n, long long i, long long s, long long cnt,
         vector<long long> &a) {
  if (i >= n && cnt > 0) {
    if (s != 0)
      return 0;
    else
      return 1;
  }
  if (i >= n && cnt == 0) return 0;
  bool a1 = sum(n, i + 1, s, cnt, a);
  bool b = sum(n, i + 1, s - a[i], cnt + 1, a);
  bool c = sum(n, i + 1, s + a[i], cnt + 1, a);
  bool d = (a1 | b | c);
  return d;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(15);
  long long T;
  cin >> T;
  while (T--) {
    long long n, q, k, m, u, v, w, x;
    string s, t;
    cin >> n >> m;
    long long ans = 0;
    m++;
    vector<long long> a(31), b(31);
    for (int(i) = (0); (i) < (31); (i)++) {
      a[i] = n % 2;
      b[i] = m % 2;
      n /= 2;
      m /= 2;
    }
    reverse((a).begin(), (a).end());
    reverse((b).begin(), (b).end());
    for (int(i) = (0); (i) < (31); (i)++) {
      if (a[i] && !b[i]) break;
      if (!a[i] && b[i]) ans = ans | (1 << (30 - i));
    }
    cout << ans << "\n";
  }
  return 0;
}

```