408136: GYM102994 A Everyone Loves Playing Games

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

A. Everyone Loves Playing Gamestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

One day, Acesrc and Roundgod are playing an interesting game called Important Choice Pairs of Cakes (ICPC).

In this game, there is a variable $$$X$$$. Initially, $$$X$$$ is equal to $$$0$$$. $$$N$$$ pairs of numbers ($$$x_i,y_i$$$) are given to Acesrc while $$$M$$$ pairs ($$$x'_i,y'_i$$$) are given to Roundgod.

Firstly, for every pair ($$$x_i,y_i$$$), Acesrc will choose either $$$x_i$$$ or $$$y_i$$$. Suppose he choose $$$k$$$, $$$X$$$ will be changed to ($$$X$$$ $$$\oplus \ k$$$). ($$$\oplus$$$ denotes bitwise exclusive or)

After Acesrc's $$$N$$$ operations, Roundgod will do the same with his $$$M$$$ pairs.

They know about each other's pairs from the beginning. Acesrc wishes the final value of $$$X$$$ to be as great as possible while Roundgod wishes it to be as small as possible.

Acesrc and Roundgod are very clever boys and they will choose the best strategy. Can you predict the final value of $$$X$$$?

Input

There are multiple test cases. The first line of the input contains an integer $$$T$$$ ($$$1 \le T \le 20$$$), indicating the number of test cases. For each test case:

The first line contains two integers $$$N$$$ and $$$M$$$ ($$$1 \leq N,M \leq 10000$$$).

Then $$$N$$$ lines follow. In each line, there are two integers $$$x_i,y_i$$$ ($$$1 \leq x_i,y_i \leq 10^{18}$$$), representing Acesrc's pairs.

Then $$$M$$$ lines follow. In each line, there are two integers $$$x'_i,y'_i$$$ ($$$1 \leq x'_i,y'_i \leq 10^{18}$$$), representing Roundgod's pairs.

Output

For each test case, you should output a single integer in a line as your answer.

ExampleInput
2
1 1
6 3
4 1
2 2
1 3
4 6
5 4
2 2
Output
2
2
Note

In the first sample, if Acesrc chooses $$$6$$$, Roundgod will choose $$$4$$$ and the result will be $$$2$$$.

If Acesrc chooses $$$3$$$, Roundgod will choose $$$1$$$ and the result will also be $$$2$$$.

Therefore the answer is $$$2$$$.

加入题单

算法标签: