from collections import Counter

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

src = [tuple(map(int,input().split())) for i in range(N)]

ctr = Counter()

for row in src:

    ctr += Counter(row[1:])



ans = 0

for v in list(ctr.values()):

    if v==N:

        ans += 1

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

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

from collections import Counter

c = Counter()

for a in A:

    c += Counter(a[1:])

ans = 0

for v in list(c.values()):

    if v==N: ans += 1

print(ans)
from collections import Counter

N, M = list(map(int, input().split()))
src = [tuple(map(int, input().split())) for i in range(N)]
ctr = Counter()
for row in src:
    ctr += Counter(row[1:])
ans = 0
for v in list(ctr.values()):
    if v == N:
        ans += 1
print(ans)

N, M = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(N)]
from collections import Counter

c = Counter()
for a in A:
    c += Counter(a[1:])
ans = 0
for v in list(c.values()):
    if v == N:
        ans += 1
print(ans)

+N, M = list(map(int, input().split())) +A = [list(map(int, input().split())) for i in range(N)] -N, M = list(map(int, input().split())) -src = [tuple(map(int, input().split())) for i in range(N)] -ctr = Counter() -for row in src: -    ctr += Counter(row[1:]) +c = Counter() +for a in A: +    c += Counter(a[1:]) -for v in list(ctr.values()): +for v in list(c.values()):