Kiteretsu goes to his Chemistry Lab to perform the perfect reaction. In his lab, he found
reagents numbered to . The reagent has two properties - and .
A reaction can be performed between the reagents and only if .
If a reaction is performed between reagents and , amount of heat is produced. Out of this, is absorbed and the rest heat is released. Here, denotes the bitwise XOR operation.
More formally, in a reaction between reagents and , the heat released is given by:
Find the maximum possible heat which can be released in a reaction.
Note: The input of this problem is large, so use fast input/output methods.
Input Format
- The first line will contain - the number of test cases. Then the test cases follow.
- First line of each test case contains two integers .
- Second line of each test case contains integers .
- Third line of each test case contains integers
Output Format
For each test case, print a single line, a single integer denoting the maximum possible heat that can be released in a reaction.
Constraints
- Sum of over all test cases does not exceed .
Sample Input 1
2
5 2
2 4 5 5 6
1 3 2 2 5
2 3
2 3
1 2
Sample Output 1
6
-7
Explanation
Test Case : Let us choose and . Since , a reaction can take place.
The heat released in this reaction is . It can be proven that for no other reaction, the heat released is greater than .
Some other reactions can take place between , . Note that no reaction is possible between as .
Test Case : The only possible reaction is between reagents and . The heat released in this reaction is .
ConversionConversion EmoticonEmoticon