FGROUP - Find the group

no tags 

 

You are given 2 arrays of size N and M.You have to answer Q queries where each query consists of a number.
You have to find out in which of the two arrays is the given number in.

 

You are given 2 arrays of size N and M.You have to answer Q queries where each query consists of a number.

You have to find out in which of the two arrays is the given number in.

 

 

Input

 

The first line gives the number of test cases T (T <= 10).

Then T test case follow.

The first line of each test case gives the value of N.The second line contains N space separated integers.

The third line of each test case gives the value of M.The fourth line contains M space separated integers.

Next line gives the value of Q, number of queries to be answered.

Q lines follow containing a number each on one line.

 

Output

 

For each test case, in response to the Q queries for that test-case print Q lines.

If the number is present in both arrays, print "both" ( without quotes ).

Else print the array in which the number is in ( 1 or 2 ).

If the number is not present in both arrays,print -1.

 

Print a new line after every test case.

 

Example

Input:
2
3
5 8 2
4
3 8 6 1
4
5
8
6
9
3
1 2 3
3
1 2 3
3
1
2
3

Output:
1
both
2
-1

both
both
both
Constraints:
 N,M <= 20000
Q <= 30000
All numbers in the input will be less than 50000.
Explanation:

For the first case, 5 is present in array 1 only, 8 is present in both arrays, 6 is present in array 2 only while 6 is not present in either array.




Added by:.:: Pratik ::.
Date:2010-04-16
Time limit:0.409s-2.212s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: NODEJS OBJC PERL6 SQLITE VB.NET