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

flag = [0]*m

for i in range(n):

    a = list(map(int,input().split()))

    for j in a[1:]:

        flag[j-1]+=1

print((sum(x==n for x in flag)))
n,m = list(map(int,input().split()))

x = [0]*(m+1)

for i in range(n):

    d = list(map(int,input().split()))

    for i in d[1:]:

        x[i] += 1

print((x.count(n)))

n, m = list(map(int, input().split()))
flag = [0] * m
for i in range(n):
    a = list(map(int, input().split()))
    for j in a[1:]:
        flag[j - 1] += 1
print((sum(x == n for x in flag)))

n, m = list(map(int, input().split()))
x = [0] * (m + 1)
for i in range(n):
    d = list(map(int, input().split()))
    for i in d[1:]:
        x[i] += 1
print((x.count(n)))

-flag = [0] * m +x = [0] * (m + 1) -    a = list(map(int, input().split())) -    for j in a[1:]: -        flag[j - 1] += 1 -print((sum(x == n for x in flag))) +    d = list(map(int, input().split())) +    for i in d[1:]: +        x[i] += 1 +print((x.count(n)))