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.
import java.util.*; // Implicit import
import java.io.*;
import java.math.BigInteger; // Explicit import

public class A {

	static FastReader		sc	= new FastReader();
	static PrintWriter	out	= new PrintWriter(System.out);

	static int xorarr[];
	public static void main(String[] args) throws Exception {
		xorarr=new int[500000];
		for(int i=1;i<500000;i++) {
			xorarr[i]=i^xorarr[i-1];
		}
		int t = sc.ni();
		while (t-- > 0) {
			A.go();
		}
		out.flush();

	}

	// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Code Starts <<<<<<<<<<<<<<<<<<<<<<<<<<<<< //

static void go() {
int a=sc.ni();
int b=sc.ni();
int len=a;
if(a==1 && b==1) {
	out.println(3);
	return;
}
int valtillhere=xorarr[a-1];
if(valtillhere==b) {
	out.println(len);
}else {
	if(a==1) {
		out.println(len+1);
	}else {
		out.println(len+a-1);
	}
}

}
 static class helper{
	 int x,y;
	 helper(int x,int y){
		 this.x=x;
		 this.y=y;
	 }
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + x;
		result = prime * result + y;
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		helper other = (helper) obj;
		if (x != other.x)
			return false;
		if (y != other.y)
			return false;
		return true;
	}
 }

	// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Code Ends <<<<<<<<<<<<<<<<<<<<<<<<<<<<< //
	static long	fact[];
	static long	invfact[];

	static long ncr(int n, int k) {
		if (k < 0 || k > n) {
			return 0;
		}
		long x = fact[n] % mod;
		long y = invfact[k] % mod;
		long yy = invfact[n - k] % mod;
		long ans = (x * y) % mod;
		ans = (ans * yy) % mod;
		return ans;
	}

	static long gcd(long a, long b) {
		if (b == 0) {
			return a;
		}
		return gcd(b, a % b);
	}

	static int	prime[]	= new int[200005];
	static int	N				= 200005;

	static void sieve() {

		for (int i = 0; i < N; i++) {
			prime[i] = i;
		}
		for (int i = 2; i * i <= N; i++) {
			if (prime[i] == i) {
				prime[i] = i;
				for (int j = i; j < N; j += i) {
					prime[j] = i;
				}
			}
		}
	}

	static int gcd(int a, int b) {
		if (b == 0) {
			return a;
		}
		return gcd(b, a % b);
	}

	static void sort(int[] a) {
		ArrayList<Integer> aa = new ArrayList<>();
		for (Integer i : a) {
			aa.add(i);
		}
		Collections.sort(aa);
		for (int i = 0; i < a.length; i++)
			a[i] = aa.get(i);
	}

	static void sort(long[] a) {
		ArrayList<Long> aa = new ArrayList<>();
		for (Long i : a) {
			aa.add(i);
		}
		Collections.sort(aa);
		for (int i = 0; i < a.length; i++)
			a[i] = aa.get(i);
	}

	static int mod = (int) 1000000007;

	static long pow(long x, long y) {
		long res = 1l;
		while (y != 0) {
			if (y % 2 == 1) {
				res = (x % mod * res % mod) % mod;
			}
			y /= 2;
			x = (x % mod * x % mod) % mod;
		}
		return res % mod;
	}

	// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Fast IO <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< //

	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 ni() {
			return Integer.parseInt(next());
		}

		long nl() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		int[] intArray(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = sc.ni();
			return a;
		}

		long[] longArray(int n) {
			long a[] = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = sc.nl();
			return a;
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}