D = int(eval(input()))

c = list(map(int, input().split()))

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

t = [int(eval(input())) for _ in range(D)]



last = [-1] * 26

S = 0

for d in range(D):

    S += s[d][t[d] - 1]



    last[t[d] - 1] = d

    for i in range(26):

        S -= c[i] * (d - last[i])



    print(S)

D = int(eval(input()))

c = list(map(int, input().split()))

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

t = [int(eval(input())) for _ in range(D)]





lasts = [[-1] * 26 for _ in range(D + 1)]

S = 0

for d in range(D):

    S += s[d][t[d] - 1]



    for i in range(26):

        if i == t[d] - 1:

            lasts[d+1][i] = d

        else:

            lasts[d+1][i] = lasts[d][i]



    for i in range(26):

        S -= c[i] * (d - lasts[d+1][i])



    print(S)

D = int(eval(input()))
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
t = [int(eval(input())) for _ in range(D)]
last = [-1] * 26
S = 0
for d in range(D):
    S += s[d][t[d] - 1]
    last[t[d] - 1] = d
    for i in range(26):
        S -= c[i] * (d - last[i])
    print(S)

D = int(eval(input()))
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
t = [int(eval(input())) for _ in range(D)]
lasts = [[-1] * 26 for _ in range(D + 1)]
S = 0
for d in range(D):
    S += s[d][t[d] - 1]
    for i in range(26):
        if i == t[d] - 1:
            lasts[d + 1][i] = d
        else:
            lasts[d + 1][i] = lasts[d][i]
    for i in range(26):
        S -= c[i] * (d - lasts[d + 1][i])
    print(S)

-last = [-1] * 26 +lasts = [[-1] * 26 for _ in range(D + 1)] -    last[t[d] - 1] = d -        S -= c[i] * (d - last[i]) +        if i == t[d] - 1: +            lasts[d + 1][i] = d +        else: +            lasts[d + 1][i] = lasts[d][i] +    for i in range(26): +        S -= c[i] * (d - lasts[d + 1][i])