403182: GYM101061 K Army

Memory Limit:64 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

K. Armytime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard output

When HIAST CPC 2016 was finally over, Feras found himself taking the last place !!

He went home exhausted from all the hard problems he had tried to solve in the contest. In order to take his mind off the problems for a while, he decided to play a PC game. Yes, he decided to play his favorite game Army (Army is an advanced version of the well known game Red Alert).

Rules for Army are quite simple. On the battlefield you have the following 3 concepts:

  1. N soldiers numbered from 1 to N.
  2. M places numbered from 1 to M.
  3. W type of weapons numbered from 1 to W.

Each one of your soldiers may guard exactly one place, and each place may be guarded by exactly one soldier. In order for a soldier to guard a certain place, he needs to have exactly one weapon. Your job is to cover as many places as possible. However, it's not that simple.

On one hand, your soldiers are a bit moody. For the ith soldier you are given two lists:

  1. The first list is for places consisting of Yi places. It means that the ith soldier prefers exactly Yi places. Therefore, the ith soldier will only guard one of the places mentioned in his places list.
  2. The second list is for weapons consisting of Zi weapons. It means that the ith soldier prefers exactly Zi weapons. Therefore, the ith soldier will only guard one of the places that has one of the weapons mentioned in his weapons list.

On the other hand, for each place you are given a list consisting of Ck weapons indicating the weapons available at the kth place. Therefore, if you assign soldier x to guard place y, then he can only have one of the weapons available at place y. Please note that it's possible that many places have the same kind of weapons. i.e. 2 places may have the same kind of weapons.

Place y is called "guarded" if there is a soldier x standing on place y and carrying a weapon z, such that:

  1. Weapon z is one of the weapons available at place y.
  2. Weapon z is one of the weapons preferred by soldier x.
  3. Place y is one of the places preferred by soldier x.

Feras is exhausted from HIAST CPC, and he felt frustrated because he couldn't find the perfect distribution for soldiers in order to guard as many places as possible, so he asked for your help. Can you help poor Feras to feel better about him self? Help him calculate the maximum number of places that could be guarded.

Input

The first line of input contains a single integer T, indicating the number of test cases.

The second line of input consists of three integers (1 ≤ N ≤ 100), (1 ≤ M ≤ 100) and (1 ≤ W ≤ 100), indicating the number of soldiers, the number of places and the number of weapons, respectively.

Then N lines follow. The ith line of them describes the places which the ith soldier prefers. Each line starts with an integer Yi denoting the number of the places, followed by Yi distinct integers (1 ≤ yi ≤ M) separated by spaces indicating the list of places which the ith soldier prefers.

N lines follow. The ith line of them describes the weapons which the ith soldier prefers. Each line starts with an integer Zi denoting the number of the weapons, followed by Zi distinct integers (1 ≤ zi ≤ W) separated by spaces indicating the list of weapons which the ith soldier prefers.

M lines follow. The kth line of them describes the weapons available at the kth place. Each line starts with an integer Ck denoting the number of the weapons, followed by Ck distinct integers (1 ≤ ck ≤ W) separated by spaces indicating the list of the weapons available at the kth place.

Output

For each test case print a single line containing the maximum number of places that can be guarded.

ExampleInput
2
3 4 5
2 1 2
2 1 4
2 3 4
1 3
2 2 5
3 1 3 4
2 3 2
1 2
1 4
3 5 1 3
2 2 2
1 1
1 2
1 1
1 2
1 2
1 1
Output
3
0

加入题单

算法标签: