CF1567B.MEXor Mixup

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

MEXor Mixup

Alice gave Bob two integers aa and bb (a>0a \gt 0 and b0b \ge 0). Being a curious boy, Bob wrote down an array of non-negative integers with MEX\operatorname{MEX} value of all elements equal to aa and XOR\operatorname{XOR} value of all elements equal to bb.

What is the shortest possible length of the array Bob wrote?

Recall that the MEX\operatorname{MEX} (Minimum EXcluded) of an array is the minimum non-negative integer that does not belong to the array and the XOR\operatorname{XOR} of an array is the bitwise XOR of all the elements of the array.

Input

The input consists of multiple test cases. The first line contains an integer tt (1t51041 \leq t \leq 5 \cdot 10^4) — the number of test cases. The description of the test cases follows.

The only line of each test case contains two integers aa and bb (1a31051 \leq a \leq 3 \cdot 10^5; 0b31050 \leq b \leq 3 \cdot 10^5) — the MEX\operatorname{MEX} and XOR\operatorname{XOR} of the array, respectively.

Output

For each test case, output one (positive) integer — the length of the shortest array with MEX\operatorname{MEX} aa and XOR\operatorname{XOR} bb. We can show that such an array always exists.

Note

In the first test case, one of the shortest arrays with MEX\operatorname{MEX} 11 and XOR\operatorname{XOR} 11 is [0,2020,2021][0, 2020, 2021].

In the second test case, one of the shortest arrays with MEX\operatorname{MEX} 22 and XOR\operatorname{XOR} 11 is [0,1][0, 1].

It can be shown that these arrays are the shortest arrays possible.

Samples

5
1 1
2 1
2 0
1 10000
2 10000
3
2
3
2
3

在线编程 IDE

建议全屏模式获得最佳体验