N = int(eval(input()))

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



res = 0

for k in range(1 << N):

    bits = [(k >> i) & 1 for i in range(N)]

    flag = True

    for i, a in enumerate(A):

        if bits[i] == 0:

            continue

        for x, y in a:

            if bits[x - 1] == y:

                continue

            flag = False

    if flag:

        res = max(res, sum(bits))



print(res)

N = int(eval(input()))

XY = [[list(map(int, input().split())) for _ in range(int(eval(input())))] for _ in range(N)]



res = 0

for k in range(1 << N):

    bits = [(k >> i) & 1 for i in range(N)]

    flag = True

    for i in range(N):

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

            continue

        for x, y in XY[i]:

            if bits[x - 1] == y:

                continue

            flag = False

    if flag:

        res = max(res, sum(bits))

print(res)

N = int(eval(input()))
A = [
    [list(map(int, input().split())) for _ in range(int(eval(input())))]
    for _ in range(N)
]
res = 0
for k in range(1 << N):
    bits = [(k >> i) & 1 for i in range(N)]
    flag = True
    for i, a in enumerate(A):
        if bits[i] == 0:
            continue
        for x, y in a:
            if bits[x - 1] == y:
                continue
            flag = False
    if flag:
        res = max(res, sum(bits))
print(res)

N = int(eval(input()))
XY = [
    [list(map(int, input().split())) for _ in range(int(eval(input())))]
    for _ in range(N)
]
res = 0
for k in range(1 << N):
    bits = [(k >> i) & 1 for i in range(N)]
    flag = True
    for i in range(N):
        if (k >> i) & 1 == 0:
            continue
        for x, y in XY[i]:
            if bits[x - 1] == y:
                continue
            flag = False
    if flag:
        res = max(res, sum(bits))
print(res)

-A = [ +XY = [ -    for i, a in enumerate(A): -        if bits[i] == 0: +    for i in range(N): +        if (k >> i) & 1 == 0: -        for x, y in a: +        for x, y in XY[i]: