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

aa = [0] * m

for _ in range(n):

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

    for ai in tmp[1:]:

        aa[ai-1] += 1



ans = 0

for i in aa:

    if i == n:

        ans += 1

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

like = [0] * m

for _ in range(n):

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

    for i in range(1, ka[0]+1):

        like[ka[i]-1] += 1



ans = 0

for li in like:

    if li == n:

        ans += 1

print(ans)
n, m = list(map(int, input().split()))
aa = [0] * m
for _ in range(n):
    tmp = list(map(int, input().split()))
    for ai in tmp[1:]:
        aa[ai - 1] += 1
ans = 0
for i in aa:
    if i == n:
        ans += 1
print(ans)

n, m = list(map(int, input().split()))
like = [0] * m
for _ in range(n):
    ka = list(map(int, input().split()))
    for i in range(1, ka[0] + 1):
        like[ka[i] - 1] += 1
ans = 0
for li in like:
    if li == n:
        ans += 1
print(ans)

-aa = [0] * m +like = [0] * m -    tmp = list(map(int, input().split())) -    for ai in tmp[1:]: -        aa[ai - 1] += 1 +    ka = list(map(int, input().split())) +    for i in range(1, ka[0] + 1): +        like[ka[i] - 1] += 1 -for i in aa: -    if i == n: +for li in like: +    if li == n: