Intermediate1400

Соседний XOR

Codeforces
View on Codeforces
Time: 2 secondsMemory: 256 megabytes

You're given an array a of length n. For each index i such that 1 ≤ i n, you can perform the following operation at most once :

You can choose indices and perform the operations in any sequential order.

Given another array b of length n, determine if it is possible to transform a to b.

Input

Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^4). The description of the test cases follows. The first line of each test case contains one integer n (2 ≤ n ≤ 2 · 10^5).The second line of each test case contains n integers a_1, a_2, …, a_n (0 ≤ a_i 2^30).The third line of each test case contains n integers b_1, b_2, …, b_n (0 ≤ b_i 2^30).It is guaranteed that the sum of n over all test cases does not exceed 2 · 10^5.

Output

For each test case, output "YES" (quotes excluded) if a can be transformed to b; otherwise, output "NO". 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.

Examples

Input
7 5 1 2 3 4 5 3 2 7 1 5 3 0 0 1 1 0 1 3 0 0 1 0 0 0 4 0 0 1 2 1 3 3 2 6 1 1 4 5 1 4 0 5 4 5 5 4 3 0 1 2 2 3 2 2 10 10 11 10
Output
YES NO NO NO YES NO NO

Note

In the first test case, you can perform the operations in the following order: Choose index i=3 and assign a_3 := a_3 ⊕ a_4 = 7, and a becomes [1, 2, 7, 4, 5]. Choose index i=4 and assign a_4 := a_4 ⊕ a_5 = 1, and a becomes [1, 2, 7, 1, 5]. Choose index i=1 and assign a_1 := a_1 ⊕ a_2 = 3, and a becomes [3, 2, 7, 1, 5].

brute forcegreedy

Discussion

(0)
Sign in to join the discussion.
Loading editor...
0 online