n,k = list(map(int,input().split()))

boats = [list(map(int,input().split())) for i in range(k)]

r = eval(input())

hate = [list(map(int,input().split())) for i in range(r)]

blue = [0]*51

for i,j in hate:

	for boat in boats:

		if i in boat[1:] and j in boat[1:]:

			blue[i] = 1

			blue[j] = 1

print(sum(blue))
n,k = list(map(int,input().split()))

boats = [list(map(int,input().split()))[1:] for i in range(k)]

r = eval(input())

hate = [list(map(int,input().split())) for i in range(r)]

blue = [0]*51

for i,j in hate:

	for boat in boats:

		if i in boat and j in boat:

			blue[i] = 1

			blue[j] = 1

print(sum(blue))
n, k = list(map(int, input().split()))
boats = [list(map(int, input().split())) for i in range(k)]
r = eval(input())
hate = [list(map(int, input().split())) for i in range(r)]
blue = [0] * 51
for i, j in hate:
    for boat in boats:
        if i in boat[1:] and j in boat[1:]:
            blue[i] = 1
            blue[j] = 1
print(sum(blue))

n, k = list(map(int, input().split()))
boats = [list(map(int, input().split()))[1:] for i in range(k)]
r = eval(input())
hate = [list(map(int, input().split())) for i in range(r)]
blue = [0] * 51
for i, j in hate:
    for boat in boats:
        if i in boat and j in boat:
            blue[i] = 1
            blue[j] = 1
print(sum(blue))

-boats = [list(map(int, input().split())) for i in range(k)] +boats = [list(map(int, input().split()))[1:] for i in range(k)] -        if i in boat[1:] and j in boat[1:]: +        if i in boat and j in boat: