N=int(input())
F=[ [[0 for _ in range(2)] for _ in range(5)] for _ in range(N)]
P= [[0 for _ in range(10)] for _ in range(N)]
total= [[0 for _ in range(5)] for _ in range(2)]

for i in range(N):
  tmp=list( map(int,input().split()) )
  for j in range(5):
    for k in range(2):
      F[i][j][k]=tmp[j+k]
for i in range(N):
  P[i]=list(map(int,input().split()))

for i in range(N):
  tmp=0
  for j in range(5):
    for k in range(2):
      tmp += 