N = int(eval(input()))

T = [[-1] * N for _ in range(N)]

for i in range(N):

    for _ in range(int(eval(input()))):

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

        T[i][x - 1] = y



ans = 0

for i in range(1 << N):

    is_kind = [i >> j & 1 for j in range(N)]

    found = True

    for j in range(N):

        if not is_kind[j]:

            continue

        for k in range(N):

            if j == k or T[j][k] == -1 or T[j][k] == is_kind[k]:

                continue

            found = False

        if not found:

            break

    if found:

        ans = max(ans, sum(is_kind))

print(ans)

N = int(eval(input()))

T = []

for i in range(N):

    for _ in range(int(eval(input()))):

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

        T.append((i, x - 1, y))



ans = 0

for i in range(1 << N):

    is_kind = [i >> j & 1 for j in range(N)]

    if all(not is_kind[j] or is_kind[x] == y for j, x ,y in T):

        ans = max(ans, sum(is_kind))

print(ans)

N = int(eval(input()))
T = [[-1] * N for _ in range(N)]
for i in range(N):
    for _ in range(int(eval(input()))):
        x, y = list(map(int, input().split()))
        T[i][x - 1] = y
ans = 0
for i in range(1 << N):
    is_kind = [i >> j & 1 for j in range(N)]
    found = True
    for j in range(N):
        if not is_kind[j]:
            continue
        for k in range(N):
            if j == k or T[j][k] == -1 or T[j][k] == is_kind[k]:
                continue
            found = False
        if not found:
            break
    if found:
        ans = max(ans, sum(is_kind))
print(ans)

N = int(eval(input()))
T = []
for i in range(N):
    for _ in range(int(eval(input()))):
        x, y = list(map(int, input().split()))
        T.append((i, x - 1, y))
ans = 0
for i in range(1 << N):
    is_kind = [i >> j & 1 for j in range(N)]
    if all(not is_kind[j] or is_kind[x] == y for j, x, y in T):
        ans = max(ans, sum(is_kind))
print(ans)

-T = [[-1] * N for _ in range(N)] +T = [] -        T[i][x - 1] = y +        T.append((i, x - 1, y)) -    found = True -    for j in range(N): -        if not is_kind[j]: -            continue -        for k in range(N): -            if j == k or T[j][k] == -1 or T[j][k] == is_kind[k]: -                continue -            found = False -        if not found: -            break -    if found: +    if all(not is_kind[j] or is_kind[x] == y for j, x, y in T):