n = int(eval(input()))

a = []

xy = []

for i in range(n):

    a.append(int(eval(input())))

    xy.append([list(map(int, input().split())) for i in range(a[-1])])

ans = 0

for i in range(2**n):

    x = [1] * n

    for j in range(n):

        if (i>>j)&1:

            x[j] = 0

    flag = False

    for j in range(n):

        for k in range(a[j]):

            if x[j] == 1:

                if x[xy[j][k][0]-1] != xy[j][k][1]:

                    flag = True

                    break

        if flag:

            break

    if flag:

        continue

    ans = max(ans, x.count(1))

print(ans)
n = int(eval(input()))

a = [0] * n

xy = [[]] * n

for i in range(n):

    a[i] = int(eval(input()))

    xy[i] = [list(map(int, input().split())) for j in range(a[i])]

ans = 0

for i in range(2**n):

    tf = [False] * n

    for j in range(n):

        if (i>>j) & 1:

            tf[j] = True

    flag = False

    for j in range(n):

        for k in xy[j]:

            if tf[j] and k[1] != tf[k[0]-1]:

                flag = True

                break

        if flag:

            break

    if flag:

        continue

    ans = max(ans, tf.count(True))

print(ans)
n = int(eval(input()))
a = []
xy = []
for i in range(n):
    a.append(int(eval(input())))
    xy.append([list(map(int, input().split())) for i in range(a[-1])])
ans = 0
for i in range(2**n):
    x = [1] * n
    for j in range(n):
        if (i >> j) & 1:
            x[j] = 0
    flag = False
    for j in range(n):
        for k in range(a[j]):
            if x[j] == 1:
                if x[xy[j][k][0] - 1] != xy[j][k][1]:
                    flag = True
                    break
        if flag:
            break
    if flag:
        continue
    ans = max(ans, x.count(1))
print(ans)

n = int(eval(input()))
a = [0] * n
xy = [[]] * n
for i in range(n):
    a[i] = int(eval(input()))
    xy[i] = [list(map(int, input().split())) for j in range(a[i])]
ans = 0
for i in range(2**n):
    tf = [False] * n
    for j in range(n):
        if (i >> j) & 1:
            tf[j] = True
    flag = False
    for j in range(n):
        for k in xy[j]:
            if tf[j] and k[1] != tf[k[0] - 1]:
                flag = True
                break
        if flag:
            break
    if flag:
        continue
    ans = max(ans, tf.count(True))
print(ans)

-a = [] -xy = [] +a = [0] * n +xy = [[]] * n -    a.append(int(eval(input()))) -    xy.append([list(map(int, input().split())) for i in range(a[-1])]) +    a[i] = int(eval(input())) +    xy[i] = [list(map(int, input().split())) for j in range(a[i])] -    x = [1] * n +    tf = [False] * n -            x[j] = 0 +            tf[j] = True -        for k in range(a[j]): -            if x[j] == 1: -                if x[xy[j][k][0] - 1] != xy[j][k][1]: -                    flag = True -                    break +        for k in xy[j]: +            if tf[j] and k[1] != tf[k[0] - 1]: +                flag = True +                break -    ans = max(ans, x.count(1)) +    ans = max(ans, tf.count(True))