N = int(input())
scoreCard = [list(map(int, input().split())) for _ in range(N)]
for i in range(N):
score = sum(scoreCard[i][j] for j in range(3) if all(scoreCard[k][j] != scoreCard[i][j] for k in range(N) if k != i))
print(score)
N = int(input())
scoreCard = [list(map(int, input().split())) for _ in range(N)]
for i in range(N):
score = sum(scoreCard[i][j] for j in range(3) if all(scoreCard[k][j] != scoreCard[i][j] for k in range(N) if k != i))
print(score)