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.
//package Java;
import java.io.*;
import java.text.DecimalFormat;
import java.util.*;
import java.util.Map.Entry;

public class Main {
	static final PrintWriter out = new PrintWriter(System.out, true);
    static final FastScanner sc = new FastScanner();
    public static void main(String[] args)  {
    		int t=sc.nextInt();
    		long p[]=new long[400005];
    		for(int i=1;i<p.length;i++) {
    			p[i]=(p[i-1]^i);
    		}
    		  while(t-->0) {
    			  int a=sc.nextInt();
    			  int b=sc.nextInt();
    			  long ans=p[a-1];
    			  int c=a;
//    			  System.out.println(ancs+" "+cc+" "+ans+" "+c);
    			  if(ans==b) {
    				  out.println(c);
    			  }else {
    				  if((ans^b)!=a) {
    					  out.println(c+1);
    				  }else {
    					  out.println(c+2);
    				  }
    			  }
    		 }
    		out.close();
    }
    static int bs(ArrayList<int []>a,int i,int n,int d) {
    	int x=a.get(i)[0];
    	int l=i+1,r=n-1;
    	int ans=i;
    	while(l<=r) {
    		int m=(l+(r-l)/2);
    		if(x+d>(a.get(m)[0])){
    			ans=m;
    			l=m+1;
    		}else {
    			r=m-1;
    		}
    	}
    	return ans;
    }
	  static void sieveOfEratosthenes(int n,int a[],boolean prime[])
	    {
	        for (int i = 0; i <= n; i++)
	            prime[i] = true;
	        	int ii=0;
	        for (int p = a[ii];ii<n;ii++)
	        {
	            if (prime[p] == true)
	            {
	                for (int i = p * p; i <= n; i += p)
	                    prime[i] = false;
	            }
	        }
	    }
	  public static double log2(long m)
	    {
	        double result = (double)(Math.log(m) / Math.log(2));
	  
	        return result;
	    }
	     static double setPrecision(double ans,int k){
	    	 double y=Math.pow(10,k);
	    	 return Math.round(ans*y)/y;
	     }
	  public static double log2(double m)
	    {
	        double result = (double)(Math.log(m) / Math.log(2));
	  
	        return result;
	    }
	public static void sort(long[] arr){//because Arrays.sort() uses quicksort which is in worst O(n^2)
		//Collections.sort() uses merge sort
		ArrayList<Long> ttttt = new ArrayList<Long>();
		for(long y: arr)ttttt.add(y);Collections.sort(ttttt);
		for(int i=0; i < arr.length; i++)arr[i] = ttttt.get(i);
	}
	public static void sort(int[] arr){//because Arrays.sort() uses quicksort which is dumb
		//Collections.sort() uses merge sort
		ArrayList<Integer> ttttt = new ArrayList<>();
		for(int y: arr)ttttt.add(y);Collections.sort(ttttt);
		for(int i=0; i < arr.length; i++)arr[i] = ttttt.get(i);
	}
	static boolean check(double[] a,double m,int n,int k) {
		int ans=0;
		for(int i=0;i<n;i++) {
			ans+=(Math.floor(a[i]/m));
			if(ans>=k) return true;
		}
		return ans>=k;
	}
	     static boolean isKthBitSet(long n, int k) { 
			if ((n & (1 << (k - 1))) > 0) 
			return true;
			else
			return false;
			
		 } 
	     long modpow(long a,long b,int m) {
	    	 if(b==0) return 1;
	    	 if(b==1) return a;
	    	 long ans=0;
	    	 long t=modpow(a,b/2,m);
	    	 ans=modmul(t,t,m);
	    	 if(b%2!=0) ans=modmul(a,ans,m);
	    	 return ans;
	     }
		long modmul(long a,long b,int m) {
			return mod(mod(a,m)*mod(b,m),m);
		}
		long mod(long x,int m) {
			return ((x%m)+m)%m;
		}
		 static int octaltodecimal(int deciNum)
		    {
		        int octalNum = 0, countval = 1;
		        int dNo = deciNum;
		        while (deciNum != 0) {
		 
		            // decimals remainder is calculated
		            int remainder = deciNum % 8;
		 
		            // storing the octalvalue
		            octalNum += remainder * countval;
		 
		            // storing exponential value
		            countval = countval * 10;
		            deciNum /= 8;
		        }
		       return octalNum;
		    }
		
	  public static int floorSqrt(int x) 
	    { 
	        // Base Cases 
	        if (x == 0 || x == 1) 
	            return x; 
	  
	        // Do Binary Search for floor(sqrt(x)) 
	        int start = 1, end = x, ans=0; 
	        while (start <= end) 
	        { 
	            int mid = (start + end) / 2; 
	  
	            // If x is a perfect square 
	            if (mid*mid == x) 
	                return mid; 
	  
	            // Since we need floor, we update answer when mid*mid is 
	            // smaller than x, and move closer to sqrt(x) 
	            if (mid*mid < x) 
	            { 
	                start = mid + 1; 
	                ans = mid; 
	            } 
	            else   // If mid*mid is greater than x 
	                end = mid-1; 
	        } 
	        return ans; 
	    } 
		static int div(int n,int b) {
			int g=-1;
			for(int i=2;i<=Math.sqrt(n);i++) {
				if(n%i==0&&i!=b) {
					g=i;
					break;
				}
			}
			return g;
		}
	 
	  
	  public static int gcd(int a, int b) 
	    { 
	        if (a == 0) 
	            return b; 
	          
	        return gcd(b%a, a); 
	    } 
	   public static int lcm(int a, int b)  
	  {  
	     return (a*b)/gcd(a, b);  
	  }  
	   public static boolean isPrime1(int n) {
           if (n <= 1) {
               return false;
           }
           if (n == 2) {
               return true;
           }
           for (int i = 2; i <= Math.sqrt(n) + 1; i++) {
               if (n % i == 0) {
                   return false;
               }
           }
           return true;
       }
       public static boolean isPrime(int n) {
           if (n <= 1) {
               return false;
           }
           if (n == 2) {
               return true;
           }
           if (n % 2 == 0) {
               return false;
           }
           for (int i = 3; i <= Math.sqrt(n) + 1; i = i + 2) {
               if (n % i == 0) {
                   return false;
               }
           }
           return true;
       }
	      
       static class FastScanner {
           BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
           StringTokenizer strToken = new StringTokenizer("");
           String next() {
        	   while (!strToken.hasMoreTokens()) {
        		   try {
        			   strToken = new StringTokenizer(input.readLine()); 
        		   }  catch (IOException e) { 
        			    e.printStackTrace();
        			  } 
        	   } return strToken.nextToken(); 
        	}
           String nextLine() {
        	   String strrrrr = ""; try {
        		   strrrrr = input.readLine(); 
        	   } catch (IOException e) {
        			   e.printStackTrace(); 
        		}
        	   return strrrrr; 
           }
           int nextInt() {
        	   return Integer.parseInt(next()); 
        	}
           int[] nextIntArray(int n) {
        	   int[] a = new int[n]; 
        	   for (int i = 0; i < n; i++) a[i] = nextInt(); 
        	   return a; 
           }
           long nextLong() {
        	   return Long.parseLong(next()); 
        	}
           long[] nextLongArray(int n) {
        	   long[] a = new long[n];
        	   for (int i = 0; i < n; i++) a[i] = nextLong(); 
        	   return a; 
        	}
           double nextDouble() {
        	   return Double.parseDouble(next()); 
           }
       }
}
//
//class Pair{
//  int value;
//  int distance;
//  Pair(int value,int distance){
//      this.value=value;
//      this.distance=distance;
//  }
//  
//}
//class sortbydistance implements Comparator<Pair>{
//
//	@Override
//	public int compare(Pair o1, Pair o2) {
//		return o1.distance-o2.distance;
//	}
//	
//}
//class Solution
//{
//  static int[] dijkstra(int n, ArrayList<ArrayList<ArrayList<Integer>>> adj, int S)
//  {
//  	 PriorityQueue<Pair>set=new PriorityQueue<>(new sortbydistance());
//      int dis[]=new int[n];
//      Arrays.fill(dis,Integer.MAX_VALUE);
//      dis[0]=0;
//      while(set.isEmpty()==false) {
//      	Pair p=set.poll();
//      	int u=p.value;
//      	for(int i=0;i<adj.get(u).size();i++) {
//      		int v=adj.get(u).get(i).get(0);
//      		int wt=adj.get(u).get(i).get(1);
//      		if(dis[v]>dis[u]+wt) {
//      			if(dis[v]!=Integer.MAX_VALUE) {
//      				set.remove(new Pair(dis[v],v));
//      			}
//      			dis[v]=dis[u]+wt;
//      			set.add(new Pair(v,dis[v]));
//      		}
//      		
//      	}
//      }
//      
//      
//      return dis;
//  }
//}
//