n = int(eval(input()))

a = [0]*n

x = [[] for i in range(n)]

y = [[] for i in range(n)]

for i in range(n):

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

    for j in range(a[i]):

        tmp1,tmp2 = list(map(int,input().split()))

        x[i].append(tmp1-1)

        y[i].append(tmp2)



ans = 0

honest = [0]*n

for i in range(2**n): #bit全探索

    for j in range(n):

        if((i>>j)&1):

            honest[j] = 1

        else:

            honest[j] = 0

            

        f = True

        for k in range(n):

            for l in range(a[k]):

                if(honest[k]==1 and y[k][l]!=honest[x[k][l]]):

                    f = False

                    break

        if f:

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



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

a = [0]*n

x = [[] for i in range(n)]

y = [[] for i in range(n)]

for i in range(n):

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

    for j in range(a[i]):

        tmp1,tmp2 = list(map(int,input().split()))

        x[i].append(tmp1-1)

        y[i].append(tmp2)



ans = 0

honest = [0]*n

cnt=0

for i in range(2**n): #bit全探索

    for j in range(n):

        if((i>>j)&1):

            honest[j] = 1

            cnt+=1

        else:

            honest[j] = 0

            

    f = True

    for k in range(n):

        if honest[k]!=1:

            continue

        for l in range(a[k]):

            if y[k][l]!=honest[x[k][l]]:

                f = False

                break

    if f:

        ans = max(ans,cnt)

    cnt=0



print(ans)
n = int(eval(input()))
a = [0] * n
x = [[] for i in range(n)]
y = [[] for i in range(n)]
for i in range(n):
    a[i] = int(eval(input()))
    for j in range(a[i]):
        tmp1, tmp2 = list(map(int, input().split()))
        x[i].append(tmp1 - 1)
        y[i].append(tmp2)
ans = 0
honest = [0] * n
for i in range(2**n):  # bit全探索
    for j in range(n):
        if (i >> j) & 1:
            honest[j] = 1
        else:
            honest[j] = 0
        f = True
        for k in range(n):
            for l in range(a[k]):
                if honest[k] == 1 and y[k][l] != honest[x[k][l]]:
                    f = False
                    break
        if f:
            ans = max(ans, honest.count(1))
print(ans)

n = int(eval(input()))
a = [0] * n
x = [[] for i in range(n)]
y = [[] for i in range(n)]
for i in range(n):
    a[i] = int(eval(input()))
    for j in range(a[i]):
        tmp1, tmp2 = list(map(int, input().split()))
        x[i].append(tmp1 - 1)
        y[i].append(tmp2)
ans = 0
honest = [0] * n
cnt = 0
for i in range(2**n):  # bit全探索
    for j in range(n):
        if (i >> j) & 1:
            honest[j] = 1
            cnt += 1
        else:
            honest[j] = 0
    f = True
    for k in range(n):
        if honest[k] != 1:
            continue
        for l in range(a[k]):
            if y[k][l] != honest[x[k][l]]:
                f = False
                break
    if f:
        ans = max(ans, cnt)
    cnt = 0
print(ans)

+cnt = 0 +            cnt += 1 -        f = True -        for k in range(n): -            for l in range(a[k]): -                if honest[k] == 1 and y[k][l] != honest[x[k][l]]: -                    f = False -                    break -        if f: -            ans = max(ans, honest.count(1)) +    f = True +    for k in range(n): +        if honest[k] != 1: +            continue +        for l in range(a[k]): +            if y[k][l] != honest[x[k][l]]: +                f = False +                break +    if f: +        ans = max(ans, cnt) +    cnt = 0