#P7639. [2018年杭电多校]Rikka with Time Complexity

[2018年杭电多校]Rikka with Time Complexity

Rikka with Time Complexity

Problem Description

Input

The first line contains a single number t(1t105)t(1 \leq t \leq 10^5), the number of testcases. For each testcase, the first line contains two integers a,b(1a,b3)a,b(1 \leq a,b \leq 3), the length of AA and BB. The second line contains aa integers AiA_i and the third line contains bb integers Bi(1Ai,Bi109)B_i(1 \leq A_i,B_i \leq 10^9), which describe AA and BB.

Output

For each testcase, output a single line with a single integer, the answer.

Sample Input

3

1 1

1

2

2 2

1 2

2 1

1 3

1

1000000000 3 3

Sample Output

1

-1

-1

Source

2018 Multi-University Training Contest 9