description: 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.
solution: import java.io.ByteArrayInputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.PrintWriter;
  import java.util.Arrays;
  import java.util.InputMismatchException;
  import java.util.PriorityQueue;
  
  public class Main {
  
  	private static final String NO = "NO";
  	private static final String YES = "YES";
  	InputStream is;
  	PrintWriter out;
  	String INPUT = "";
  
  	private static final int MOD = (int) (1e9 + 7);
  
  	void solve() {
  		int T = ni();
  		for (int i = 0; i < T; i++)
  			solve(i);
  	}
  
  	void solve(int nth) {
  		int n = ni();
  		int m = ni();
  		++m;
  		int ans = 0;
  		for (int i = 30; i >= 0; --i) {
  			int a = n >> i & 1;
  			int b = m >> i & 1;
  			if (a == b)
  				continue;
  			else if (a > b)
  				break;
  			else
  				ans += 1 << i;
  		}
  		out.println(ans);
  	}
  
  	void run() throws Exception {
  		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
  		out = new PrintWriter(System.out);
  
  		long s = System.currentTimeMillis();
  		solve();
  		out.flush();
  		if (!INPUT.isEmpty())
  			tr(System.currentTimeMillis() - s + "ms");
  	}
  
  	public static void main(String[] args) throws Exception {
  		new Main().run();
  	}
  
  	private byte[] inbuf = new byte[1024];
  	public int lenbuf = 0, ptrbuf = 0;
  
  	private int readByte() {
  		if (lenbuf == -1)
  			throw new InputMismatchException();
  		if (ptrbuf >= lenbuf) {
  			ptrbuf = 0;
  			try {
  				lenbuf = is.read(inbuf);
  			} catch (IOException e) {
  				throw new InputMismatchException();
  			}
  			if (lenbuf <= 0)
  				return -1;
  		}
  		return inbuf[ptrbuf++];
  	}
  
  	private boolean isSpaceChar(int c) {
  		return !(c >= 33 && c <= 126);
  	}
  
  	private int skip() {
  		int b;
  		while ((b = readByte()) != -1 && isSpaceChar(b))
  			;
  		return b;
  	}
  
  	private double nd() {
  		return Double.parseDouble(ns());
  	}
  
  	private char nc() {
  		return (char) skip();
  	}
  
  	private char[] nc(int n) {
  		char[] ret = new char[n];
  		for (int i = 0; i < n; i++)
  			ret[i] = nc();
  		return ret;
  	}
  
  	private String ns() {
  		int b = skip();
  		StringBuilder sb = new StringBuilder();
  		while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != '
  									// ')
  			sb.appendCodePoint(b);
  			b = readByte();
  		}
  		return sb.toString();
  	}
  
  	private char[] ns(int n) {
  		char[] buf = new char[n];
  		int b = skip(), p = 0;
  		while (p < n) {
  			if (!(isSpaceChar(b)))
  				buf[p++] = (char) b;
  			b = readByte();
  		}
  		return n == p ? buf : Arrays.copyOf(buf, p);
  	}
  
  	private char[][] nm(int n, int m) {
  		char[][] map = new char[n][];
  		for (int i = 0; i < n; i++)
  			map[i] = ns(m);
  		return map;
  	}
  
  	private int[] na(int n) {
  		int[] a = new int[n];
  		for (int i = 0; i < n; i++)
  			a[i] = ni();
  		return a;
  	}
  
  	private Integer[] na2(int n) {
  		Integer[] a = new Integer[n];
  		for (int i = 0; i < n; i++)
  			a[i] = ni();
  		return a;
  	}
  
  	private int[][] na(int n, int m) {
  		int[][] a = new int[n][];
  		for (int i = 0; i < n; i++)
  			a[i] = na(m);
  		return a;
  	}
  
  	private int ni() {
  		int num = 0, b;
  		boolean minus = false;
  		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
  			;
  		if (b == '-') {
  			minus = true;
  			b = readByte();
  		}
  
  		while (true) {
  			if (b >= '0' && b <= '9') {
  				num = num * 10 + (b - '0');
  			} else {
  				return minus ? -num : num;
  			}
  			b = readByte();
  		}
  	}
  
  	private Long[] nl2(int n) {
  		Long[] a = new Long[n];
  		for (int i = 0; i < n; i++)
  			a[i] = nl();
  		return a;
  	}
  
  	private long[] nl(int n) {
  		long[] a = new long[n];
  		for (int i = 0; i < n; i++)
  			a[i] = nl();
  		return a;
  	}
  
  	private long[][] nl(int n, int m) {
  		long[][] a = new long[n][];
  		for (int i = 0; i < n; i++)
  			a[i] = nl(m);
  		return a;
  	}
  
  	private long nl() {
  		long num = 0;
  		int b;
  		boolean minus = false;
  		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
  			;
  		if (b == '-') {
  			minus = true;
  			b = readByte();
  		}
  
  		while (true) {
  			if (b >= '0' && b <= '9') {
  				num = num * 10 + (b - '0');
  			} else {
  				return minus ? -num : num;
  			}
  			b = readByte();
  		}
  	}
  
  	private static void tr(Object... o) {
  		System.out.println(Arrays.deepToString(o));
  	}
  
  }
  