QOJ.ac

QOJ

実行時間制限: 1.0 s メモリ制限: 256 MB 満点: 100 ハック可能 ✓

#14531. Find the Minimum

統計

Mandy has discovered two interesting sequences of length $n$, denoted as $a$ and $b$. She defines the "boredom" of a sequence as the XOR sum of all its elements.

She wants these two sequences to be as interesting as possible; specifically, she wants the more "bored" sequence to be as interesting as possible. She believes that swapping elements at corresponding positions between the two sequences is harmless, and she can perform this operation any number of times.

Now, she wants to know: in the most interesting scenario, what is the boredom of the more bored sequence?

Formally, you have two sequences $a$ and $b$ of length $n$. You can perform any number of operations where you choose an index $i$ ($1 \le i \le n$) and swap $a_i$ and $b_i$. You want to minimize $\max\{f(a), f(b)\}$, where for any sequence $A$, $f(A) = \bigoplus_{i=1}^n A_i$ ($\oplus$ denotes bitwise XOR).

Input

The first line contains an integer $T$ ($1 \le T \le 10^5$), representing the number of test cases.

For each test case: The first line contains an integer $n$ ($1 \le n \le 10^6$). The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i < 2^{31}$). The third line contains $n$ integers $b_1, b_2, \dots, b_n$ ($0 \le b_i < 2^{31}$).

It is guaranteed that for all test cases, $\sum n \le 10^6$.

Output

For each test case, output a single integer representing the minimum $\max\{f(a), f(b)\}$.

Examples

Input 1

2
1
1
2
2
1 2
2 1

Output 1

2
0

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.