P19268 [CodeChef] JOKRBTMN
提高-
题目描述

Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well.

During a fight with the Joker, Batman's eyes lose the capability to distinguish between some pairs of colors.

Each color has an integer ID from 1 to N. There are M lists where each color belongs to exactly one list. Batman can distinguish colors belonging to different lists, but he cannot distinguish colors belonging to the same list.

Given a strip of L colors, find the different number of segments Batman will see as a result of his disability. Two positions of the strip are said to belong to the same segment if they are adjacent on the strip and Batman cannot distinguish their colors. See the sample explanation for clarity.

------ Input Format ------

  • The first line contains an integer T, the number of test cases. Then the test cases follow.
  • The first line contain three integers N, M, and L - the number of colors, the number of lists, and the length of the strip, respectively.
  • Each of the next M lines describes a list. It begins with an integer K_{i}, the length of the i-th list, followed by $K_{i} integers A_{i1}, A_{i2}, \ldots, A_{iK_{i}} -$ the color IDs of the i-th list.
  • The next line contains $L integers S_{1}, S_{2}, \ldots, S_{L} -$ the color IDs of the strip.

------ Output Format ------

For each test case, output in a single line the answer to the problem.

------ Constraints ------

$1 ≤ T ≤ 10$
$1 ≤ M ≤ N ≤ 10^{5}$
$1 ≤ L ≤ 10^{5}$
$1 ≤ K_{i}, A_{ij}, S_{i} ≤ N$
$\sum_{i=1}^{M} K_{i} = N$
- Each color belongs to exactly one list.

----- Sample Input 1 ------
3
2 2 2
1 2
1 1
2 1
2 2 4
1 1
1 2
1 2 2 1
3 2 3
2 1 3
1 2
1 3 1
----- Sample Output 1 ------
2
3
1
----- explanation 1 ------
Test Case 1: Since the strip is composed of colors from different lists, the answer is the length of the strip, which is $2$.

Test Case 2: The first and second index have colors from different lists, and the third and fourth index have colors from different lists. So the strip is seen to be composed of $3$ consecutive segments.

Test Case 3: Since the strip is composed of colors from the same list, the answer is $1$ segment.

输入格式

见题面

输出格式

见题面

样例输入
3 2 2 2 1 2 1 1 2 1 2 2 4 1 1 1 2 1 2 2 1 3 2 3 2 1 3 1 2 1 3 1
样例输出
2 3 1