N = int(input())
A = input().split(' ')
Q = int(input())
bc = [input().split() for _ in range(Q)]
A = [int(i) for i in A]
for i in range(Q):
    bc[i] = [int(j) for j in bc[i]]
# print(bc)

for i in range(Q):
    for j in range(len(A)):
        if A[j] == bc[i][0]:
            A[j] = bc[i][1]
    ans = sum(A)
    print(ans)
