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.*;
  import java.util.*;
  
  public class Mikasa implements Runnable {
  
     void solve() {
        int t = ri();
        while (t-- > 0) {
           int n = ri(), m = ri();
           m++;
           int ans = 0;
  
           for (int i = 30; i >= 0; i--) {
              int nb = (1 << i) & n;
              int mb = (1 << i) & m;
              if (nb == 0 && mb > 0) {
                 ans |= (1 << i);
              } else if (nb > 1 && mb == 0) {
                 break;
              }
           }
           println(ans);
        }
     }
  
     /************************************************************************************************************************************************/
     public static void main(String[] args) throws IOException {
        new Thread(null, new Mikasa(), "1").start();
     }
  
     static PrintWriter out = new PrintWriter(System.out);
     static Reader read = new Reader();
     static StringBuilder sbr = new StringBuilder();
     static int mod = (int) 1e9 + 7;
     static int dmax = Integer.MAX_VALUE;
     static long lmax = Long.MAX_VALUE;
     static int dmin = Integer.MIN_VALUE;
     static long lmin = Long.MIN_VALUE;
     static int[] dprimes = new int[] { 1, 11, 101, 1087, 99991, 100001, 1000003, 15485863, 999999937 };
  
     @Override
     public void run() {
        solve();
        out.close();
     }
  
     static class Reader {
        private byte[] buf = new byte[1024];
        private int index;
        private InputStream in;
        private int total;
  
        public Reader() {
           in = System.in;
        }
  
        public int scan() throws IOException {
           if (total < 0)
              throw new InputMismatchException();
           if (index >= total) {
              index = 0;
              total = in.read(buf);
              if (total <= 0)
                 return -1;
           }
           return buf[index++];
        }
  
        public int intNext() throws IOException {
           int integer = 0;
           int n = scan();
           while (isWhiteSpace(n))
              n = scan();
           int neg = 1;
           if (n == '-') {
              neg = -1;
              n = scan();
           }
           while (!isWhiteSpace(n)) {
              if (n >= '0' && n <= '9') {
                 integer *= 10;
                 integer += n - '0';
                 n = scan();
              } else
                 throw new InputMismatchException();
           }
           return neg * integer;
        }
  
        public double doubleNext() throws IOException {
           double doub = 0;
           int n = scan();
           while (isWhiteSpace(n))
              n = scan();
           int neg = 1;
           if (n == '-') {
              neg = -1;
              n = scan();
           }
           while (!isWhiteSpace(n) && n != '.') {
              if (n >= '0' && n <= '9') {
                 doub *= 10;
                 doub += n - '0';
                 n = scan();
              } else
                 throw new InputMismatchException();
           }
           if (n == '.') {
              n = scan();
              double temp = 1;
              while (!isWhiteSpace(n)) {
                 if (n >= '0' && n <= '9') {
                    temp /= 10;
                    doub += (n - '0') * temp;
                    n = scan();
                 } else
                    throw new InputMismatchException();
              }
           }
           return doub * neg;
        }
  
        public String read() throws IOException {
           StringBuilder sb = new StringBuilder();
           int n = scan();
           while (isWhiteSpace(n))
              n = scan();
           while (!isWhiteSpace(n)) {
              sb.append((char) n);
              n = scan();
           }
           return sb.toString();
        }
  
        public String rline() throws IOException {
           StringBuilder sb = new StringBuilder();
           int n = scan();
           while (n != '\n') {
              sb.append((char) n);
              n = scan();
           }
           return sb.toString();
        }
  
        private boolean isWhiteSpace(int n) {
           if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
              return true;
           return false;
        }
     }
  
     static void print(Object object) {
        out.print(object);
     }
  
     static void println(Object object) {
        out.println(object);
     }
  
     static int[] iArr(int len) {
        return new int[len];
     }
  
     static long[] lArr(int len) {
        return new long[len];
     }
  
     static long min(long a, long b) {
        return Math.min(a, b);
     }
  
     static int min(int a, int b) {
        return Math.min(a, b);
     }
  
     static long max(Long a, Long b) {
        return Math.max(a, b);
     }
  
     static int max(int a, int b) {
        return Math.max(a, b);
     }
  
     static int ri() {
        try {
           return read.intNext();
        } catch (IOException e) {
           e.printStackTrace();
        }
        System.exit(2);
        return -1;
     }
  
     static long rl() {
        try {
           return Long.parseLong(read.read());
        } catch (IOException e) {
           e.printStackTrace();
        }
        System.exit(2);
        return -1;
     }
  
     static String rs() {
        try {
           return read.read();
        } catch (IOException e) {
           e.printStackTrace();
        }
        System.exit(2);
        return "";
     }
  
     static String rline() {
        try {
           return read.rline();
        } catch (IOException e) {
           e.printStackTrace();
        }
        System.exit(2);
        return "";
     }
  
     static char rc() {
        return rs().charAt(0);
     }
  
     static double rd() {
        try {
           return read.doubleNext();
        } catch (IOException e) {
           e.printStackTrace();
        }
        System.exit(2);
        return -1;
     }
  }
  