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 com.company;

import java.io.*;
import java.lang.reflect.Array;
import java.text.DecimalFormat;
import java.util.*;

public class Main {

    static boolean[] primecheck = new boolean[1000002];

    public static void main(String[] args) throws IOException {
        OutputStream outputStream = System.out;
        FastReader in = new FastReader();
        PrintWriter out = new PrintWriter(outputStream);
        PROBLEM solver = new PROBLEM();
        int t = 1;
        t = in.nextInt();
        for (int i = 0; i < t; i++) {
            solver.solve(in, out);
        }
        out.close();
    }



    static class PROBLEM {

        public void solve(FastReader in, PrintWriter out) {

//            int s = in.nextInt(), n = in.nextInt();
//            int y = s, len = 0, niner = 0;
//            while(y>0){
//                len++;
//                y/=10;
//            }
//
//            y = s;
//            int ninerMax = 0;
//            while(ninerMax < s){
//                ninerMax = ninerMax*10 + 9;
//                niner++;
//            }
//
//            if(ninerMax > s){
//                niner--;
//                ninerMax -= 9;
//                ninerMax/=10;
//            }
//            //out.println("Max = " + ninerMax + " niners = " + niner + " len = " + len);
//
//            if(n>niner){
//
//            }



           int a = in.nextInt(), b = in.nextInt();

           int ans = a;
           int xor = 0;
           int rem = (a-1)%4;

           if(rem == 0) xor = a-1;
           else if(rem == 1) xor = 1;
           else if(rem == 2) xor = a;
           else if(rem == 3) xor = 0;

           int req = 0;
           if(xor != b){
               req = xor^b;
               if(req == a) ans++;
               ans += 1;
           }

            //out.println("XOR = " + xor + " req = " + req);

           out.println(ans);


        }


    }

    static boolean isPalindromeI(int n){

        int d = 0;
        int y = n;
        while(y>0){
            d++;
            y/=10;
        }

        int[] a = new int[d];
        for (int i = 0; i < d; i++) {
            a[i] = n%10;
            n/=10;
        }

        System.out.println(Arrays.toString(a));
        for (int i = 0; i < d / 2; i++) {
            if(a[i] != a[d-i-1]) return false;
        }
        return true;
    }

    static boolean isPalindrome(char[] s){
        int flag = 1;
        for (int i = 0; i < s.length; i++) {
            if(s[i] != s[s.length-1-i]){
                flag = 0;
                break;
            }
        }
        if(flag == 1) return true;
        else return false;
    }

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

    static boolean isSquare(double a) {
        boolean isSq = false;
        double b = Math.sqrt(a);
        double c = Math.sqrt(a) - Math.floor(b);

        if (c == 0) isSq = true;

        return isSq;
    }

    static int exponentMod(int A, int B, int C) {

        // Base cases
        if (A == 0)
            return 0;
        if (B == 0)
            return 1;

        // If B is even
        long y;
        if (B % 2 == 0) {
            y = exponentMod(A, B / 2, C);
            y = (y * y) % C;
        }

        // If B is odd
        else {
            y = A % C;
            y = (y * exponentMod(A, B - 1,
                    C) % C) % C;
        }

        return (int) ((y + C) % C);
    }


    static class pair implements Comparable<pair>{
        int x,y;
        pair(int xi, int yi){
            x=xi;
            y=yi;
        }
        @Override
        public int compareTo(pair other){
            if(this.x>other.x){return 1;}
            if(this.x<other.x){return -1;}
            if(this.y>other.y){return 1;}
            if(this.y<other.y){return -1;}
            return 0;
        }
    }

//    public static class Pair<U extends Comparable<U>, V extends Comparable<V>> implements Comparable<Pair<U, V>> {
//        public U x;
//        public V y;
//
//        public Pair(U x, V y) {
//            this.x = x;
//            this.y = y;
//        }
//
//        public int hashCode() {
//            return (x == null ? 0 : x.hashCode() * 31) + (y == null ? 0 : y.hashCode());
//        }
//
//        public boolean equals(Object o) {
//            if (this == o)
//                return true;
//            if (o == null || getClass() != o.getClass())
//                return false;
//            Pair<U, V> p = (Pair<U, V>) o;
//            return (x == null ? p.x == null : x.equals(p.x)) && (y == null ? p.y == null : y.equals(p.y));
//        }
//
//        public int compareTo(Pair<U, V> b) {
//            int cmpU = x.compareTo(b.x);
//            return cmpU != 0 ? cmpU : y.compareTo(b.y);
//        }
//
//        public String toString() {
//            return String.format("(%s, %s)", x.toString(), y.toString());
//        }
//
//    }

    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());
        }

        char nextChar() {
            return next().charAt(0);
        }

        boolean nextBoolean() {
            return !(nextInt() == 0);
        }
        // boolean nextBoolean(){return Boolean.parseBoolean(next());}

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

        public int[] readArray(int size) {
            int[] array = new int[size];
            for (int i = 0; i < size; i++) array[i] = nextInt();
            return array;
        }

    }

    private static int[] mergeSort(int[] array) {

        //array.length replaced with ctr
        int ctr = array.length;
        if (ctr <= 1) {
            return array;
        }

        int midpoint = ctr / 2;

        int[] left = new int[midpoint];
        int[] right;

        if (ctr % 2 == 0) {
            right = new int[midpoint];
        } else {
            right = new int[midpoint + 1];
        }

        for (int i = 0; i < left.length; i++) {
            left[i] = array[i];
        }

        for (int i = 0; i < right.length; i++) {
            right[i] = array[i + midpoint];
        }

        int[] result = new int[array.length];

        left = mergeSort(left);
        right = mergeSort(right);

        result = merge(left, right);

        return result;
    }

    private static int[] merge(int[] left, int[] right) {

        int[] result = new int[left.length + right.length];
        int leftPointer = 0, rightPointer = 0, resultPointer = 0;

        while (leftPointer < left.length || rightPointer < right.length) {

            if (leftPointer < left.length && rightPointer < right.length) {

                if (left[leftPointer] < right[rightPointer]) {
                    result[resultPointer++] = left[leftPointer++];
                } else {
                    result[resultPointer++] = right[rightPointer++];
                }
            } else if (leftPointer < left.length) {
                result[resultPointer++] = left[leftPointer++];
            } else {
                result[resultPointer++] = right[rightPointer++];
            }
        }
        return result;
    }

    public static void Sieve(int n) {

        Arrays.fill(primecheck, true);
        primecheck[0] = false;
        primecheck[1] = false;

        for (int i = 2; i * i < n + 1; i++) {
            if (primecheck[i]) {
                for (int j = i * 2; j < n + 1; j += i) {
                    primecheck[j] = false;
                }
            }
        }
    }
}


