Friendly Arrays
Contest: CodeTON Round 6 (Div. 1 + Div. 2, Rated, Prizes!)
Difficulty rating: 1200
Tags: bitmasks, greedy, math

You are given two arrays of integers — $$$a_1, \ldots, a_n$$$ of length $$$n$$$, and $$$b_1, \ldots, b_m$$$ of length $$$m$$$. You can choose any element $$$b_j$$$ from array $$$b$$$ ($$$1 \leq j \leq m$$$), and for all $$$1 \leq i \leq n$$$ perform $$$a_i = a_i | b_j$$$. You can perform any number of such operations.

After all the operations, the value of $$$x = a_1 \oplus a_2 \oplus \ldots \oplus a_n$$$ will be calculated. Find the minimum and maximum values of $$$x$$$ that could be obtained after performing any set of operations.

Above, $$$|$$$ is the bitwise OR operation, and $$$\oplus$$$ is the bitwise XOR operation.

Input format:
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. This is followed by the description of the test cases.

The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 2 \cdot 10^5$$$) — the sizes of arrays $$$a$$$ and $$$b$$$.

The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 10^9$$$) — the array $$$a$$$.

The third line of each test case contains $$$m$$$ integers $$$b_1, b_2, \ldots, b_m$$$ ($$$0 \leq b_i \leq 10^9$$$) — the array $$$b$$$.

It is guaranteed that the sum of values of $$$n$$$ and $$$m$$$ across all test cases does not exceed $$$2 \cdot 10^5$$$.

Output format:
For each test case, output $$$2$$$ numbers: the minimum and maximum possible values of $$$x$$$ after performing any set of operations.

Constraints:
Time limit: 2.0 s
Memory limit: 256.0 MB

Note:
In the first test case, if we apply the operation with element $$$b_1 = 1$$$, the array $$$a$$$ will become $$$[1, 1]$$$, and $$$x$$$ will be $$$0$$$. If no operations are applied, then $$$x = 1$$$.

In the second test case, if no operations are applied, then $$$x = 2$$$. If we apply the operation with $$$b_1 = 1$$$, then $$$a = [1, 1, 3]$$$, and $$$x = 3$$$.

Example input:
2
2 3
0 1
1 2 3
3 1
1 1 2
1

Example output:
0 1
2 3

Editorial:
Note that after performing the operation on $$$b_j$$$, which has some bit set to 1, this bit will become 1 for all numbers in $$$a$$$ (and will remain so, as a bit cannot change from 1 to 0 in the result of an OR operation). If $$$n$$$ is even, then in the final XOR, this bit will become 0, as it will be equal to the XOR of an even number of ones. If $$$n$$$ is odd, then this bit will be 1 in the final XOR.
Therefore, if $$$n$$$ is even, by performing the operation on $$$b_j$$$, we set all the bits that are 1 in $$$b_j$$$ to 0 in the final XOR. If $$$n$$$ is odd, we do the opposite and set these bits to 1. So, if $$$n$$$ is even, the XOR does not increase when applying the operation, which means that to obtain the minimum possible XOR, we need to apply the operation to all the numbers in $$$b$$$, and the maximum XOR will be the original XOR. For odd $$$n$$$, it is the opposite: the minimum is the original XOR, and the maximum is obtained after applying the operation to all elements in $$$b$$$.
To apply the operation to all elements in $$$b$$$, it is sufficient to calculate their bitwise OR and apply the operation to the array $$$a$$$ with it.