N = int(eval(input()))



S = []

for _ in range(N):

    A = int(eval(input()))

    S.append([tuple(map(int, input().split())) for _ in range(A)])



def sol(state):

    for i, A in enumerate(S):

        if (state & (1 << i)) == 0:

            continue

        for j, s in A:

            if ((state & (1 << (j - 1))) != 0) != (s != 0):

                return 0

    return sum(map(int, bin(state)[2:]))



ans = 0

for state in range(1 << N):

    ans = max(ans, sol(state))

print(ans)

N = int(eval(input()))

A = []



for _ in range(N):

    A.append([tuple(map(int, input().split())) for _ in range(int(eval(input())))])



def exists(state):

    ret = 0

    for i in range(N):

        if ((1 << i) & state) == 0:

            continue

        ret += 1

        for x, y in A[i]:

            if ((state & (1 << (x - 1))) > 0) != (y > 0):

                return 0

    return ret



ans = 0

for state in range(1 << N):

    ans = max(ans, exists(state))

print(ans)

N = int(eval(input()))
S = []
for _ in range(N):
    A = int(eval(input()))
    S.append([tuple(map(int, input().split())) for _ in range(A)])


def sol(state):
    for i, A in enumerate(S):
        if (state & (1 << i)) == 0:
            continue
        for j, s in A:
            if ((state & (1 << (j - 1))) != 0) != (s != 0):
                return 0
    return sum(map(int, bin(state)[2:]))


ans = 0
for state in range(1 << N):
    ans = max(ans, sol(state))
print(ans)

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


def exists(state):
    ret = 0
    for i in range(N):
        if ((1 << i) & state) == 0:
            continue
        ret += 1
        for x, y in A[i]:
            if ((state & (1 << (x - 1))) > 0) != (y > 0):
                return 0
    return ret


ans = 0
for state in range(1 << N):
    ans = max(ans, exists(state))
print(ans)

-S = [] +A = [] -    A = int(eval(input())) -    S.append([tuple(map(int, input().split())) for _ in range(A)]) +    A.append([tuple(map(int, input().split())) for _ in range(int(eval(input())))]) -def sol(state): -    for i, A in enumerate(S): -        if (state & (1 << i)) == 0: +def exists(state): +    ret = 0 +    for i in range(N): +        if ((1 << i) & state) == 0: -        for j, s in A: -            if ((state & (1 << (j - 1))) != 0) != (s != 0): +        ret += 1 +        for x, y in A[i]: +            if ((state & (1 << (x - 1))) > 0) != (y > 0): -    return sum(map(int, bin(state)[2:])) +    return ret -    ans = max(ans, sol(state)) +    ans = max(ans, exists(state))