n=int(eval(input()))

X=[]*n

A=[]*n



for i in range(n):

	a=int(eval(input()))

	A.append(a)

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

	X.append(xy)



ans=0

for i in range(2**n):

	cnt=0

	for j in range(n):

		if (i>>j)&1:

			for k,l in X[j]:

				if not ((i>>(k-1))&1)==l:

					cnt=1



	if cnt==0:

		ans = max(ans,bin(i).count("1"))



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

X=[]*n

A=[]*n



for i in range(n):

	a=int(eval(input()))

	A.append(a)

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

	X.append(xy)



ans=0

for i in range(2**n):

	cnt=0

	for j in range(n):

		if (i>>j)&1:

			for k,l in X[j]:

				if not ((i>>(k-1))&1)==l:

					cnt=1

					break



	if cnt==0:

		ans = max(ans,bin(i).count("1"))



print(ans)
n = int(eval(input()))
X = [] * n
A = [] * n
for i in range(n):
    a = int(eval(input()))
    A.append(a)
    xy = [list(map(int, input().split())) for _ in range(a)]
    X.append(xy)
ans = 0
for i in range(2**n):
    cnt = 0
    for j in range(n):
        if (i >> j) & 1:
            for k, l in X[j]:
                if not ((i >> (k - 1)) & 1) == l:
                    cnt = 1
    if cnt == 0:
        ans = max(ans, bin(i).count("1"))
print(ans)

n = int(eval(input()))
X = [] * n
A = [] * n
for i in range(n):
    a = int(eval(input()))
    A.append(a)
    xy = [list(map(int, input().split())) for _ in range(a)]
    X.append(xy)
ans = 0
for i in range(2**n):
    cnt = 0
    for j in range(n):
        if (i >> j) & 1:
            for k, l in X[j]:
                if not ((i >> (k - 1)) & 1) == l:
                    cnt = 1
                    break
    if cnt == 0:
        ans = max(ans, bin(i).count("1"))
print(ans)

+                    break