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 fromto . There are 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 ofcolors, 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.
- The first line contains an integer , the number of test cases. Then the test cases follow.
- The first line contain three integers , , and – the number of colors, the number of lists, and the length of the strip, respectively.
- Each of the next lines describes a list. It begins with an integer , the length of the -th list, followed by integers – the color IDs of the -th list.
- The next line contains integers – the color IDs of the strip.
For each test case, output in a single line the answer to the problem.
- 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
Test Case 1: Since the strip is composed of colors from different lists, the answer is the length of the strip, which is.
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 ofconsecutive segments.
Test Case 3: Since the strip is composed of colors from the same list, the answer issegment.