n = int(eval(input()))

L = [[-1]*n for _ in range(n)]

for i in range(n):

    a = int(eval(input()))

    for j in range(a):

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

        x -= 1

        L[i][x] = y

#print(L)



ans = 0

for i in range(2**n):

    temp = 0

    for j in range(n):

        if (i >> j) & 1:

            temp += 1

    flag = True

    for j in range(n):

        if (i >> j) & 1:

            for k in range(n):

                #print((i >> k) & 0)

                if  L[j][k] == 1 and ((i >> k) & 1) == 0:

                    flag =  False

                elif L[j][k] == 0 and ((i >> k) & 1) != 0:

                    flag = False

                else:

                    pass

    if flag:

        ans = max(ans, temp)

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

X = [[] for _ in range(n)]

for i in range(n):

    a = int(eval(input()))

    for j in range(a):

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

        x -= 1

        X[i].append((x, y))



ans = 0

for i in range(2**n):

    t = [-1]*n

    flag = True

    cnt = 0

    for j in range(n):

        if (i >> j) & 1:

            cnt += 1

            t[j] = 1

        else:

            t[j] = 0

    for j in range(n):

        if (i >> j) & 1:

            for x, y in X[j]:

                if t[x] != y:

                    flag = False

    if flag:

        ans = max(ans, cnt)



print(ans)

n = int(eval(input()))
L = [[-1] * n for _ in range(n)]
for i in range(n):
    a = int(eval(input()))
    for j in range(a):
        x, y = list(map(int, input().split()))
        x -= 1
        L[i][x] = y
# print(L)
ans = 0
for i in range(2**n):
    temp = 0
    for j in range(n):
        if (i >> j) & 1:
            temp += 1
    flag = True
    for j in range(n):
        if (i >> j) & 1:
            for k in range(n):
                # print((i >> k) & 0)
                if L[j][k] == 1 and ((i >> k) & 1) == 0:
                    flag = False
                elif L[j][k] == 0 and ((i >> k) & 1) != 0:
                    flag = False
                else:
                    pass
    if flag:
        ans = max(ans, temp)
print(ans)

n = int(eval(input()))
X = [[] for _ in range(n)]
for i in range(n):
    a = int(eval(input()))
    for j in range(a):
        x, y = list(map(int, input().split()))
        x -= 1
        X[i].append((x, y))
ans = 0
for i in range(2**n):
    t = [-1] * n
    flag = True
    cnt = 0
    for j in range(n):
        if (i >> j) & 1:
            cnt += 1
            t[j] = 1
        else:
            t[j] = 0
    for j in range(n):
        if (i >> j) & 1:
            for x, y in X[j]:
                if t[x] != y:
                    flag = False
    if flag:
        ans = max(ans, cnt)
print(ans)

-L = [[-1] * n for _ in range(n)] +X = [[] for _ in range(n)] -        L[i][x] = y -# print(L) +        X[i].append((x, y)) -    temp = 0 +    t = [-1] * n +    flag = True +    cnt = 0 -            temp += 1 -    flag = True +            cnt += 1 +            t[j] = 1 +        else: +            t[j] = 0 -            for k in range(n): -                # print((i >> k) & 0) -                if L[j][k] == 1 and ((i >> k) & 1) == 0: +            for x, y in X[j]: +                if t[x] != y: -                elif L[j][k] == 0 and ((i >> k) & 1) != 0: -                    flag = False -                else: -                    pass -        ans = max(ans, temp) +        ans = max(ans, cnt)