import functools

print((len(functools.reduce(lambda x, y: x&y,[set(input().split()[1:]) for _ in [0]*int(input().split()[0])]))))
print((len(set.intersection(*[set(input().split()[1:]) for _ in [0]*int(input().split()[0])]))))
import functools

print(
    (
        len(
            functools.reduce(
                lambda x, y: x & y,
                [set(input().split()[1:]) for _ in [0] * int(input().split()[0])],
            )
        )
    )
)

print(
    (
        len(
            set.intersection(
                *[set(input().split()[1:]) for _ in [0] * int(input().split()[0])]
            )
        )
    )
)

-import functools - -            functools.reduce( -                lambda x, y: x & y, -                [set(input().split()[1:]) for _ in [0] * int(input().split()[0])], +            set.intersection( +                *[set(input().split()[1:]) for _ in [0] * int(input().split()[0])]