import collections
N = map(int, input().split())
A = list(map(int, input().split()))
Q = map(int, input().split())
B, C = list(map(int, input().split())),list(map(int, input().split()))

base = 0
cnt = collections.Counter(A)

for i in range(N):
    base += A[i]

Ans = []
Ans.append(base + (C[0]-B[0]) * cnt[B[0]])

for i in range(Q-1):
    if cnt[B[i+1]] != 0:
        Ans.append(Ans[i] + (C[i+1]-B[i+1]) * cnt[B[i+1]])
        for j in range(i+1):
            Ans[i+1] += B.count(C[j]) * (C[i+1] - C[j])
    else:
        Ans.append(Ans[i])

print(Ans)