SimiN and NiwiS

Time Limit: 5 Seconds    Memory Limit: 32768 KB

Simin loves french fries! 

She places n packs of french fries in a line on the table and then places a ketchup packet on top of each one. There are f types of french fries in the mix, represented with 1, 2, 3, …, f. Additionally, the ketchup packets also come in s flavors represented with 1, 2, 3, …, s. 

Simin prefers only certain ketchup flavors for each type of french fries. Niwis wants to rearrange the ketchup packets so that eventually there is still a ketchup packet on every french fries pack. Niwis would like to know if she changes the placement of the ketchup packets what is the minimum and the maximum number of packs of french fries that will go with the ketchup flavor Simin likes?

Input

The first line the input, T, is the number of test cases.

The first line of every test case consists of integers n, f and s respectively, in which 1 ≤ n ≤ 105, 1 ≤ f and s ≤ 300.

The second line consists of n integers f1, f2, …, fn which are the types of french fries on the table (1 ≤ fi ≤ f).

The third line consists of n integers s1, s2, …, sn  which are different ketchup flavors (1≤ si ≤ s).

The following f lines, denote the rows of matrix Mf*s, with each line containing s integers describing the columns. The element Mi,j is 1 if and only if Simin likes the french fries of type i with the ketchup flavor of type j, otherwise it is 0.

Output

 Considering all possible arrangements of the ketchup and french fries packets, print the minimum and the maximum number of pairs of french fries packs and ketchup flavors that Simin likes.

 

Sample Input

1
3 2 2
1 1 2
2 2 1
1 0
0 1

Sample Output

0 2
Submit

Source: 15th Iran Nationwide Internet Contest