description: Alice gave Bob two integers a and b (a > 0 and b ≥ 0). Being a curious boy, Bob wrote down an array of non-negative integers with \operatorname{MEX} value of all elements equal to a and \operatorname{XOR} value of all elements equal to b.
  
  What is the shortest possible length of the array Bob wrote?
  
  Recall that the \operatorname{MEX} (Minimum EXcluded) of an array is the minimum non-negative integer that does not belong to the array and the \operatorname{XOR} of an array is the [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of all the elements of the array.
  
  Input
  
  The input consists of multiple test cases. The first line contains an integer t (1 ≤ t ≤ 5 ⋅ 10^4) — the number of test cases. The description of the test cases follows.
  
  The only line of each test case contains two integers a and b (1 ≤ a ≤ 3 ⋅ 10^5; 0 ≤ b ≤ 3 ⋅ 10^5) — the \operatorname{MEX} and \operatorname{XOR} of the array, respectively.
  
  Output
  
  For each test case, output one (positive) integer — the length of the shortest array with \operatorname{MEX} a and \operatorname{XOR} b. We can show that such an array always exists.
  
  Example
  
  Input
  
  
  5
  1 1
  2 1
  2 0
  1 10000
  2 10000
  
  
  Output
  
  
  3
  2
  3
  2
  3
  
  Note
  
  In the first test case, one of the shortest arrays with \operatorname{MEX} 1 and \operatorname{XOR} 1 is [0, 2020, 2021].
  
  In the second test case, one of the shortest arrays with \operatorname{MEX} 2 and \operatorname{XOR} 1 is [0, 1].
  
  It can be shown that these arrays are the shortest arrays possible.
solution: import java.util.*;
  import java.lang.*;
  import java.io.*;
  
  public class ac{
  	public static int lowerbound(int arr[], int N, int X)
  		{
  			int mid;
  
  			int low = 0;
  			int high = N;
  
  			while (low < high) {
  				mid = low + (high - low) / 2;
  
  				if (X <= arr[mid]) {
  					high = mid;
  				}
  				else {
  					low = mid + 1;
  				}
  			}
  			if(low < N && arr[low] < X) {
  			   low++;
  			}
  			return low;
  		}
   long power(long x, long y, long p)
  	  {
  	    long res = 1; 
  	 
  	    x = x % p; 
  	 
  	    if (x == 0)
  	      return 0; 
  	 
  	    while (y > 0)
  	    {
  	 
  	      if ((y & 1) != 0)
  	        res = (res * x) % p;
  	
  	      y = y >> 1; // y = y/2
  	      x = (x * x) % p;
  	    }
  	    return res;
  	  }
  	public static class FastReader {
  		BufferedReader br;
  		StringTokenizer st;
  
  		public FastReader() {
  			br = new BufferedReader(new InputStreamReader(System.in));
  		}
  
  		String next() {
  			while (st == null || !st.hasMoreElements()) {
  				try {
  					st = new StringTokenizer(br.readLine());
  				} catch (IOException e) {
  					e.printStackTrace();
  				}
  			}
  			return st.nextToken();
  		}
  
  		int nextInt() {
  			return Integer.parseInt(next());
  		}
  
  		long nextLong() {
  			return Long.parseLong(next());
  		}
  
  		double nextDouble() {
  			return Double.parseDouble(next());
  		}
  
  		String nextLine() {
  			String str = "";
  			try {
  				str = br.readLine();
  			} catch (IOException e) {
  				e.printStackTrace();
  			}
  			return str;
  		}
  	}
  
  	public static int gcd(int a, int b) {
  		if (b == 0) {
  			return a;
  		} else {
  			return gcd(b, a % b);
  		}
  	}
  	///code for is prime
     public static boolean isprime(int n){
     	for(int i = 2;i*i<n;i++){
     		if(n%i==0){
     			return false;
     		}
     	}
     	return true;
     }
  
     ////arr return by this steve algoritm return boolean array where there is prime that is false other wise it is true;
    public static boolean[] steve(int n){
    	boolean arr[] = new boolean[n];
    	arr[0] = true;
    	arr[1] = true;
    	for(int i = 2;i<arr.length;i++){
    		if(isprime(i)){
    			for(int j = 2;j*i<n;j++){
    				arr[i*j]=true;
    			}
    		}
    	}
    	return arr;
    }
  
  public static void ans(){
  	PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
  		FastReader fr = new FastReader();
  	int t= fr.nextInt();
  	 int N = (int)(3e5 + 5);
  	 int ar[] = new int[N];
  	 	 for (int i = 1; i < N; i++) {
      ar[i] = ar[i - 1] ^ (i - 1);
      }
  	while(t-->0){
  		int a =  fr.nextInt();
  		int b = fr.nextInt();
  	int x = ar[a];
      
      if (x == b)System.out.println(a);
      else if ((x ^ b) == a)
      	System.out.println(a+2);
      else
      	System.out.println(a+1);
  	}
  	out.close();
  }
  public static  void main(String[] args)
  	{
  	try {
  			System.setIn(new FileInputStream("input.txt"));
  			System.setOut(new PrintStream(new FileOutputStream("output.txt")));
  		} catch (Exception e) {
  			System.err.println("Error");
  		}
  		// long starttime = System.currentTimeMillis();
  	
  		ans();
  		
  		}
  	}