N = int(eval(input()))



s = [[] for _ in range(N)]

for i in range(N):

    A = int(eval(input()))

    for _ in range(A):

        x, y = list(map(int, input().split()))

        s[i].append((x - 1, y))



result = 0

for i in range(1, 2 ** N):

    consistent = True

    for j in range(N):

        if (i >> j) & 1 == 0:

            continue

        for x, y in s[j]:

            if (i >> x) & 1 != y:

                consistent = False

                break

    if consistent:

        result = max(result, bin(i)[2:].count('1'))

print(result)

N = int(eval(input()))



evidences = [[] for _ in range(N)]

for i in range(N):

    A = int(eval(input()))

    for _ in range(A):

        x, y = list(map(int, input().split()))

        evidences[i].append((x - 1, y))



result = 0

for i in range(1, 2 ** N):

    consistent = True

    for j in range(N):

        if (i >> j) & 1 == 0:

            continue

        for x, y in evidences[j]:

            if (i >> x) & 1 != y:

                consistent = False

                break

        if not consistent:

            break

    if consistent:

        result = max(result, bin(i)[2:].count('1'))

print(result)

N = int(eval(input()))
s = [[] for _ in range(N)]
for i in range(N):
    A = int(eval(input()))
    for _ in range(A):
        x, y = list(map(int, input().split()))
        s[i].append((x - 1, y))
result = 0
for i in range(1, 2**N):
    consistent = True
    for j in range(N):
        if (i >> j) & 1 == 0:
            continue
        for x, y in s[j]:
            if (i >> x) & 1 != y:
                consistent = False
                break
    if consistent:
        result = max(result, bin(i)[2:].count("1"))
print(result)

N = int(eval(input()))
evidences = [[] for _ in range(N)]
for i in range(N):
    A = int(eval(input()))
    for _ in range(A):
        x, y = list(map(int, input().split()))
        evidences[i].append((x - 1, y))
result = 0
for i in range(1, 2**N):
    consistent = True
    for j in range(N):
        if (i >> j) & 1 == 0:
            continue
        for x, y in evidences[j]:
            if (i >> x) & 1 != y:
                consistent = False
                break
        if not consistent:
            break
    if consistent:
        result = max(result, bin(i)[2:].count("1"))
print(result)

-s = [[] for _ in range(N)] +evidences = [[] for _ in range(N)] -        s[i].append((x - 1, y)) +        evidences[i].append((x - 1, y)) -        for x, y in s[j]: +        for x, y in evidences[j]: +        if not consistent: +            break