N,M=list(map(int,input().split()))

food=set(range(1,M+1))

for i in range(N):

    K,*A=list(map(int,input().split()))

    food&=set(A)

print((len(food)))
N,M=list(map(int,input().split()))

food=set(range(1,M+1))

for i in range(N):

    A=list(map(int,input().split()[1:]))

    food&=set(A)

print((len(food)))
N, M = list(map(int, input().split()))
food = set(range(1, M + 1))
for i in range(N):
    K, *A = list(map(int, input().split()))
    food &= set(A)
print((len(food)))

N, M = list(map(int, input().split()))
food = set(range(1, M + 1))
for i in range(N):
    A = list(map(int, input().split()[1:]))
    food &= set(A)
print((len(food)))

-    K, *A = list(map(int, input().split())) +    A = list(map(int, input().split()[1:]))