


The first line of the input contains an integer, 'T,’ denoting the number of test cases.
The first line of each test case contains two space-separated integers, 'N' and ‘M’ denoting the number of elements in the first and second array.
The second line of each test case contains 'N' space-separated integers denoting the elements of the array first array.
The last line of each test case contains 'M' space-separated integers denoting the elements of the array second array.
For each test case, print a single integer - the maximum possible xor among all possible pairs.
Print the output of each test case in a separate line.
You do not need to input or print anything, and it has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= N, M <= 1000
0 <= arr1[i], arr2[i] <= 10 ^ 9
Where 'T' denotes the number of test cases, 'N', ‘M’ denotes the number of elements in the first array and second array, ‘arr1[i]', and ‘arr2[i]’ denotes the 'i-th' element of the first array and second array.
Time limit: 1 sec
SImply iterate over all possible pairs and find the maximum possible xor value.
We can maximize the bitwise ‘xor’ value for any two integers by taking their bits at ‘i- th’ position as 1 and 0 or 0 and 1. For an integer ‘X’ in binary representation, we start from its most significant bit and try to find a corresponding number ‘Y’ from available numbers such that bits at the current position of ‘X’ and ‘Y’ are different, in this way we could maximize the bitwise xor value for ‘X’. So for a 32-bit integer, we just need to iterate through all its bits and check for a corresponding integer from another array such that their xor value is maximum.
To efficiently check for the corresponding integer value in the second array we can maintain a binary trie data structure for each element in the second array. For each element in the second array we convert it into binary representation and insert the bit string into the trie. The most significant bit will be the root.
So the idea is to iterate through each element in the first array and convert it into its binary representation and iterate through its all bits starting from the most significant bit. If the current bit is ‘1’ then we move to ‘0’ child in trie if available and vice versa. At last, we will find a corresponding integer from the second array such that its xor value with the current element of the first array is maximum. At last, we will return the maximum of all such values.
The function will take two parameters: