CF2254F Whiplash
Description
Yousef has given you an even integer $ n $ and two arrays, $ a $ and $ b $ , both consisting of $ n $ non-negative integers.
You can perform the following operation on array $ a $ any number of times (possibly zero):
- Choose an index $ i $ ( $ 1 \le i \le n $ ).
- For all $ j $ such that $ 1 \le j \le n $ and $ j \neq i $ , replace $ a_j $ with $ a_j \oplus a_i $ . (Here, $ \oplus $ denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR)).
- The element $ a_i $ remains unchanged.
Determine whether it is possible to transform array $ a $ into array $ b $ using a finite number of operations.
Input Format
The first line contains an integer $ t $ ( $ 1 \le t \le 10^4 $ ) — the number of test cases. The description of the test cases follows.
The first line of each test case contains an even integer $ n $ ( $ 2 \le n \le 2 \cdot 10^5 $ ) — the length of the array.
The second line of each test case contains $ n $ integers $ a_1, a_2, \dots, a_n $ ( $ 0 \le a_i \lt 2^{30} $ ) — the elements of the array $ a $ .
The third line of each test case contains $ n $ integers $ b_1, b_2, \dots, b_n $ ( $ 0 \le b_i \lt 2^{30} $ ) — the elements of the array $ b $ .
It is guaranteed that the sum of $ n $ over all test cases does not exceed $ 2 \cdot 10^5 $ .
Output Format
For each test case, output "YES" if the array $ a $ can be transformed into array $ b $ using a finite number of operations, and "NO" otherwise.
You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
Explanation/Hint
In the first test case, starting from $ [1, 2] $ , there is no sequence of operations that ends at $ [1, 0] $ , so the answer is "NO".
In the second test case, one valid sequence is:
- Choose index $ 2 $ , $ [1, {\color{blue}{2}}, 4, 7] \rightarrow [3, {\color{blue}{2}}, 6, 5] $ .
- Choose index $ 3 $ , $ [3, 2, {\color{blue}{6}}, 5] \rightarrow [5, 4, {\color{blue}{6}}, 3] $ .
- Choose index $ 4 $ , $ [5, 4, 6, {\color{blue}{3}}] \rightarrow [6, 7, 5, {\color{blue}{3}}] $ .
In the third test case, one valid sequence is:
- Choose index $ 1 $ , $ [\color{blue}{1}, 2, 4, 8] \rightarrow [\color{blue}{1}, 3, 5, 9] $ .
- Choose index $ 2 $ , $ [1, \color{blue}{3}, 5, 9] \rightarrow [2, \color{blue}{3}, 6, 10] $ .
- Choose index $ 3 $ , $ [2, 3, \color{blue}{6}, 10] \rightarrow [4, 5, \color{blue}{6}, 12] $ .
- Choose index $ 2 $ , $ [4, \color{blue}{5}, 6, 12] \rightarrow [1, \color{blue}{5}, 3, 9] $ .
- Choose index $ 4 $ , $ [1, 5, 3, \color{blue}{9}] \rightarrow [8, 12, 10, \color{blue}{9}] $ .
- Choose index $ 1 $ , $ [\color{blue}{8}, 12, 10, 9] \rightarrow [\color{blue}{8}, 4, 2, 1] $ .