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.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

public class Practice {
	public static long mod = (long) Math.pow(10, 9) + 7;
	public static long mod2 = 998244353;
	public static int tt = 1;
	public static ArrayList<Integer> prime;
	public static long[] fac = new long[200005];
	public static long[] invfac = new long[200005];

	public static void main(String[] args) throws Exception {

		PrintWriter pw = new PrintWriter(System.out);
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int t = Integer.valueOf(br.readLine());
		while (t-- > 0) {
			String[] s1 = br.readLine().split(" ");
			long n = Integer.parseInt(s1[0]);
			long m = Integer.parseInt(s1[1]);
			int a = 0;
			for (int i = 31; i >= 0; i--) {
				// System.out.println((m >> i) & 1);
				if (((m >> i) & 1) == 0 && ((n >> i) & 1) == 1) {
					m = m | (1 << i);
					a = 1;

				} else if (a == 1) {
					// System.out.println(m+" "+i);
					if (((n >> i) & 1) == 0) {
						if (((m >> i) & 1) == 1) {
							m = m ^ (1 << i);
						}
					}

				}
			}
			if (a == 0) {
				for (int i = 0; i < 32; i++) {
					// System.out.println((m >> i) & 1);
					if (((m >> i) & 1) == 0) {
						m = m | (1 << i);
						a = 1;
						for (int j = i - 1; j >= 0; j--) {
							// System.out.println((m >> i) & 1);
							if (((m >> j) & 1) == 0 && ((n >> j) & 1) == 1) {
								m = m | (1 << i);

							} else if (a == 1) {
								// System.out.println(m+" "+i);
								if (((n >> j) & 1) == 0) {
									if (((m >> j) & 1) == 1) {
										m = m ^ (1 << j);
									}
								}

							}
						}
						a = 1;
						break;
					}
				}
			}
			// 11110001001000000
			// 10011111101111110001

			// System.out.println(m);
			pw.println(n ^ m);
		}
		pw.close();

	}

	// private static int kmp(String str) {
//		// TODO Auto-generated method stub
//		// System.out.println(str);
//		int[] pi = new int[str.length()];
//		pi[0] = 0;
//		for (int i = 1; i < str.length(); i++) {
//			int j = pi[i - 1];
//			while (j > 0 && str.charAt(i) != str.charAt(j)) {
//				j = pi[j - 1];
//			}
//			if (str.charAt(j) == str.charAt(i)) {
//				j++;
//			}
//			pi[i] = j;
//			System.out.print(pi[i]);
//		}
//		System.out.println();
//		return pi[str.length() - 1];
//	}

}

//	private static void getFac(long n, PrintWriter pw) {
//		// TODO Auto-generated method stub
//		int a = 0;
//		while (n % 2 == 0) {
//			a++;
//			n = n / 2;
//		}
//		if (n == 1) {
//			a--;
//		}
//		for (int i = 3; i <= Math.sqrt(n); i += 2) {
//			while (n % i == 0) {
//				n = n / i;
//				a++;
//			}
//		}
//		if (n > 1) {
//			a++;
//		}
//		if (a % 2 == 0) {
//			pw.println("Bob");
//		} else {
//			pw.println("Alice");
//		}
//		//System.out.println(a);
//		return;
//	}

//	private static long power(long a, long p) {
//		// TODO Auto-generated method stub
//		long res = 1;
//		while (p > 0) {
//			if (p % 2 == 1) {
//				res = (res * a) % mod;
//			}
//			p = p / 2;
//			a = (a * a) % mod;
//		}
//		return res;
//	}
//
//	private static void fac() {
//		fac[0] = 1;
//		// TODO Auto-generated method stub
//		for (int i = 1; i < fac.length; i++) {
//			if (i == 1) {
//				fac[i] = 1;
//			} else {
//				fac[i] = i * fac[i - 1];
//			}
//			if (fac[i] > mod) {
//				fac[i] = fac[i] % mod;
//			}
//		}
//	}
//
//	private static int getLower(Long long1, Long[] st) {
//		// TODO Auto-generated method stub
//		int left = 0, right = st.length - 1;
//		int ans = -1;
//		while (left <= right) {
//			int mid = (left + right) / 2;
//			if (st[mid] <= long1) {
//				ans = mid;
//				left = mid + 1;
//			} else {
//				right = mid - 1;
//			}
//		}
//		return ans;
//	}

//	private static long getGCD(long l, long m) {
//
//		long t1 = Math.min(l, m);
//		long t2 = Math.max(l, m);
//		while (true) {
//			long temp = t2 % t1;
//			if (temp == 0) {
//				return t1;
//			}
//			t2 = t1;
//			t1 = temp;
//		}
//	}