import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
Q = int(input())
BC=[]
for i in range(Q):
    BC.append(list(map(int, input().split())))
BC=np.array(BC)

for i in range(Q):
    if BC[i,0] not in A:
        pass
    else:
        for j in range(len(A)):
            if A[j]==BC[i,0]:
                A[j]=BC[i,1]
    print(np.sum(A))
