Farmer Richard has a herd of mystical cows, meticulously divided between two barns. Every cow produces mystical milk which has a magic value between and , inclusive.
Unfortunately for Richard, his wife, Dara got sick and she requires a special type of magic milk to be cured. The magic milk is obtained by combining two kinds of mystical milk from two cows, one from the first barn and one from the second barn. The magic value of the combined milk is the bitwise xor of the magic values of the two kinds of milk.
In a rather bizarre turn of events, Richard had a dream where Șogard, the magical fairy responsible for the mystical properties of his cows, delivered a message. Șogard instructed Richard that if he wanted Dara to recover, she must consume the milk with the -th smallest magic value out of all possible combinations of mystical milk.
In a hurry, Richard jumped from his bed and went to his barns, but unfortunately, his mystical cows had gone to the magic land to eat magic grass to regain their mystical strength. In his dizziness, he noted down possible scenarios, each consisting of the magic value given by Șogard, and two lists and , the magic values of milk produced by the cows in the first barn and in the second barn.
Being out of touch with programming since he embraced the tranquil life of farming, Richard turns to you for help in finding the answers to his scenarios.
Input
The first line contains the only integer , the number of scenarios Richard wrote.
The first line of each scenario contains and , the number of cows in each barn, and the position of the magic milk value he needs from the sorted list of all possible combinations.
The second line contains integers , denoting the magic values of the milk produced in the first barn.
The third line contains integers , denoting the magic values of the milk produced in the second barn.
Output data
You need to write lines, each containing one integer: the -th smallest magic value that can be obtained by mixing two kinds of milk, one from the first barn and one from the second barn.
Constraints and clarifications
- for each .
- for each .
- Additional constraint on the input: the sum of over all scenarios doesn’t exceed .
# | Points | Restrictions |
---|---|---|
1 | 0 | Examples |
2 | 10 | and the sum of over all scenarios doesn’t exceed . |
3 | 15 | and or |
4 | 30 | and the sum of over all scenarios doesn’t exceed . |
5 | 45 | No additional limitations. |
Examples
stdin
3
5 5
3 6 20 5 9
12 3 19 7 13
5 10
3 6 20 5 9
12 3 19 7 13
5 25
3 6 20 5 9
12 3 19 7 13
stdout
4
8
26
Explanation
In the sample case, the magic values in ascending order in each scenario are:
So the fifth smallest magic value is , the tenth is and the twenty fifth is .