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 = x-1

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



ans = 0

for i in range(2**n):

    cnt = 0

    temp = [-1]*n

    for j in range(n):

        if (i >> j) & 1:

            cnt += 1

            temp[j] = 1

        else:

            temp[j] = 0

    flag = True

    for j in range(n):

        if (i >> j) & 1:

            for x, y in X[j]:

                if temp[x] != y:

                    flag = False

    if flag:

        ans = max(ans, cnt)

print(ans)

n = int(eval(input()))



g = [[] 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

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



ans = 0

for i in range(2**n):

    temp = [-1]*n

    for j in range(n):

        if (i >> j) & 1:

            temp[j] = 1

        else:

            temp[j] = 0

    flag = True

    for j in range(n):

        if temp[j] == 1:

            for x, y in g[j]:

                if temp[x] != y:

                    flag = False

    if flag:

        ans = max(ans, sum(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 = x - 1
        X[i].append((x, y))
ans = 0
for i in range(2**n):
    cnt = 0
    temp = [-1] * n
    for j in range(n):
        if (i >> j) & 1:
            cnt += 1
            temp[j] = 1
        else:
            temp[j] = 0
    flag = True
    for j in range(n):
        if (i >> j) & 1:
            for x, y in X[j]:
                if temp[x] != y:
                    flag = False
    if flag:
        ans = max(ans, cnt)
print(ans)

n = int(eval(input()))
g = [[] 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
        g[i].append((x, y))
ans = 0
for i in range(2**n):
    temp = [-1] * n
    for j in range(n):
        if (i >> j) & 1:
            temp[j] = 1
        else:
            temp[j] = 0
    flag = True
    for j in range(n):
        if temp[j] == 1:
            for x, y in g[j]:
                if temp[x] != y:
                    flag = False
    if flag:
        ans = max(ans, sum(temp))
print(ans)

-X = [[] for _ in range(n)] +g = [[] for _ in range(n)] -        x = x - 1 -        X[i].append((x, y)) +        x -= 1 +        g[i].append((x, y)) -    cnt = 0 -            cnt += 1 -        if (i >> j) & 1: -            for x, y in X[j]: +        if temp[j] == 1: +            for x, y in g[j]: -        ans = max(ans, cnt) +        ans = max(ans, sum(temp))