n = int(input())
cnt = 0
for i in range(n):
a,b,c = map(int, input().split())
if (a+b+c)/3 < 60:
cnt += 1
print(cnt)
n = int(input())
cnt = 0
for i in range(n):
a,b,c = map(int, input().split())
if (a+b+c)/3 < 60:
cnt += 1
print(cnt)