n = int(eval(input()))

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

ans = -float("inf")



for i in range(n):

	a = int(eval(input()))

	for _ in range(a):

		xy[i].append(tuple(map(int, input().split())))



for i in range(1 << n):

	true_or_false = [0] * n

	flag = False

	for j in range(n):

		if (i>>j)&1:

			true_or_false[n-1-j] = 1

	for i, l in enumerate(xy):

		for x, y in l:

			if true_or_false[i] == 1:

				if true_or_false[x-1] != y:

					flag = True

	if not flag:

		ans = max(ans, len([i for i in true_or_false if i == 1]))

print(ans)

n = int(eval(input()))

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

ans = -float("inf")



for i in range(n):

	a = int(eval(input()))

	for _ in range(a):

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

		xy[i].append(tuple([x-1, y]))



for i in range(2**n):

	flag = False

	cnt = 0

	for j in range(n):

		if (i >> j) & 1:

			cnt += 1

			for x, y in xy[j]:

				if y == 1:

					if (i >> x & 1) == 0:

						flag = True

				elif y == 0:

					if (i >> x & 1) == 1:

						flag = True

	if not flag:

		ans = max(ans, cnt)

print(ans)
n = int(eval(input()))
xy = [[] for _ in range(n)]
ans = -float("inf")
for i in range(n):
    a = int(eval(input()))
    for _ in range(a):
        xy[i].append(tuple(map(int, input().split())))
for i in range(1 << n):
    true_or_false = [0] * n
    flag = False
    for j in range(n):
        if (i >> j) & 1:
            true_or_false[n - 1 - j] = 1
    for i, l in enumerate(xy):
        for x, y in l:
            if true_or_false[i] == 1:
                if true_or_false[x - 1] != y:
                    flag = True
    if not flag:
        ans = max(ans, len([i for i in true_or_false if i == 1]))
print(ans)

n = int(eval(input()))
xy = [[] for _ in range(n)]
ans = -float("inf")
for i in range(n):
    a = int(eval(input()))
    for _ in range(a):
        x, y = list(map(int, input().split()))
        xy[i].append(tuple([x - 1, y]))
for i in range(2**n):
    flag = False
    cnt = 0
    for j in range(n):
        if (i >> j) & 1:
            cnt += 1
            for x, y in xy[j]:
                if y == 1:
                    if (i >> x & 1) == 0:
                        flag = True
                elif y == 0:
                    if (i >> x & 1) == 1:
                        flag = True
    if not flag:
        ans = max(ans, cnt)
print(ans)

-        xy[i].append(tuple(map(int, input().split()))) -for i in range(1 << n): -    true_or_false = [0] * n +        x, y = list(map(int, input().split())) +        xy[i].append(tuple([x - 1, y])) +for i in range(2**n): +    cnt = 0 -            true_or_false[n - 1 - j] = 1 -    for i, l in enumerate(xy): -        for x, y in l: -            if true_or_false[i] == 1: -                if true_or_false[x - 1] != y: -                    flag = True +            cnt += 1 +            for x, y in xy[j]: +                if y == 1: +                    if (i >> x & 1) == 0: +                        flag = True +                elif y == 0: +                    if (i >> x & 1) == 1: +                        flag = True -        ans = max(ans, len([i for i in true_or_false if i == 1])) +        ans = max(ans, cnt)