#P1721D. Maximum AND
Maximum AND
Description
You are given two arrays and , consisting of integers each.
Let's define a function as follows:
- let's define an array of size , where ( denotes bitwise XOR);
- the value of the function is (i.e. bitwise AND of the entire array ).
Find the maximum value of the function if you can reorder the array in an arbitrary way (leaving the initial order is also an option).
The first line contains one integer () — the number of test cases.
The first line of each test case contains one integer () — the size of arrays and .
The second line contains integers ().
The third line contains integers ().
The sum of over all test cases does not exceed .
For each test case print one integer — the maximum value of the function if you can reorder the array in an arbitrary way.
Input
The first line contains one integer () — the number of test cases.
The first line of each test case contains one integer () — the size of arrays and .
The second line contains integers ().
The third line contains integers ().
The sum of over all test cases does not exceed .
Output
For each test case print one integer — the maximum value of the function if you can reorder the array in an arbitrary way.