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.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeSet;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class S2 {
	
	public static class Reader {
		
		static BufferedReader reader;
		static StringTokenizer tokenizer;
		
		static void init(InputStream input) {
			reader = new BufferedReader(new InputStreamReader(input));
			tokenizer = new StringTokenizer("");
		}
		
		static String next() throws IOException {
			while(!tokenizer.hasMoreTokens()) {
				tokenizer = new StringTokenizer(reader.readLine());
			}
			return tokenizer.nextToken();
		}
		
		static int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
		
		static long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		
	}

	private static long n;
	private static long k;
	private static long x;
	
	private static long nl;
	private static long ans;
	
	private final static long fd = 998244353;
	private final static long mod1 = 1000000007;
	
	
	private final static int sz = 100000;
	private static long[] arr;
	private static int[] arri;
	private static char[] str;
	
	public static class Node implements Comparable<Node> {
		long ai;
		long bi;
		public Node(long a, long b) {
			// TODO Auto-generated constructor stub
			ai=a;
			bi=b;
		}
		@Override
		public int compareTo(Node o) {
			// TODO Auto-generated method stub
			long dif = bi-o.bi;
			if(dif>0) {
				return 1;
			}
			else if(dif<0){
				return -1;
			}
			return 0;
			
		}
	}
	
	public static void main(String[] args) throws IOException {
		
		Reader.init(System.in);
		
		PrintWriter out = new PrintWriter(System.out);
		
		int tc=1;
		tc = Reader.nextInt();
		
		main_loop:
			for(int tn=0; tn<tc; tn++) {
				
				ans=0;
				
				n = Reader.nextInt();
				long m = Reader.nextInt();
				ans = solve(n,m);
								
				out.print((ans)+"\n");
			}
		
		out.flush();
		out.close();
	}
	
	private static long solve(long n, long m) {
		
		boolean[] nBits = bits(n);
		boolean[] nCopy = new boolean[32];
		for(int i=0; i<32; i++) {
			nCopy[i]=nBits[i];
		}
		boolean[] mBits = bits(m);
		
		for(int i=31; i>=0; i--) {
			if(mBits[i]) {
				nBits[i]=true;
			}
			else {
				if(nBits[i]) {
					return n^convert(nBits);
				}
			}
		}
		int i=0;
		while(nBits[i]) {
			i++;
		}
		nBits[i]=true;
		i--;
		while(i>=0) {
			if(!nCopy[i]) {
				nBits[i]=false;
			}
			i--;
		}
		return n^convert(nBits);		
	}
	
	private static long convert(boolean[] bits) {
		long num=0;
		for(int i=0; i<32; i++) {
			if( bits[i]) {
				num+=1<<i;
			}
		}
		return num;
	}
	
	private static boolean[] bits(long num) {
		int i=0;
		boolean[] bArr = new boolean[32];
		while(num>0) {
			if((num&1)==1) {
				bArr[i]=true;
			}
			i++;
			num/=2;
		}
		return bArr;
	}

	private static Long getLast(ArrayList<Long> li) {
		return li.get(li.size()-1);
	}
}