In 2020, there are C programming contests held in Indonesia, numbered from 1 to C. Each contest has zero or more tasks written for the contest. There are A task authors who can write tasks for these contests, numbered from 1 to A. The ith task author only likes the set of contests L_i ⊆ 1,2,… ,C, and only wants to write tasks for contests in L_i. Each task author cannot write more than one task for the same contest.
There are also T topics in programming contest tasks, numbered from 1 to T. For example, topic 1 might be about graph tasks, topic 2 might be about string tasks, and so on. Each task has exactly one topic. The ith task author is familiar with the set of topics F_i ⊆1,2,…,T, and only wants to write tasks about topics in F_i. Each task author cannot write more than one task about the same topic.
Additionally, each contest also has a syllabus. The jth contest syllabus contains the set of topics S_j ⊆1,2,…,T, and the topic for the tasks written for the contest must be in S_j. Each contest cannot have more than one task for the same topic.
You are a programming contest enthusiast in Indonesia. Surprisingly, you observed the following:
You want to find the maximum total number of tasks that can be written across all contests.
Input begins with a line containing three integers: ACT (1≤ A,C,T≤50000) representing the number of task authors, contests, and topics, respectively.
The next A lines each begins with an integer: ∣L_i∣ (0≤∣L_i∣≤ 2) representing the number of contests that the ith task author likes, followed by ∣L_i∣ integers: L_i\[x] (1≤L_i\[x]≤C) representing the liked contests. It is guaranteed that the values in L_i are distinct. It is also guaranteed that for all 1≤j≤C, the value j only appears at most twice in ⋃_i=1AL_i.
The next A lines each begins with an integer: ∣F_i∣ (0≤∣F_i∣≤2) representing the number of topics that the ith task author is familiar with, followed by ∣F_i∣ integers: F_i\[y] (1≤F_i\[y]≤T) representing the familiarized topics. It is guaranteed that the values in F_i are distinct. It is also guaranteed that for all 1≤k≤T, the value k only appears at most twice in ⋃_i=1AF_i.
The next C lines each begins with an integer: ∣S_j∣ (0≤∣S_j∣≤2) representing the number of topics in the jth contest syllabus, followed by ∣S_j∣ integers: S_j\[z] (1≤S_j\[z]≤ T) representing the topics in the syllabus. It is guaranteed that the values in S_j are distinct. It is also guaranteed that for all 1≤k≤T, the value k only appears at most twice in ⋃_j=1CS_j.
Output in a line an integer representing the maximum total number of tasks that can be written across all contests.