from collections import Counter
N=int(input())
A=list(map(int, input().split()))
q=int(input())
Q=[list(map(int, input().split())) for _ in range(q)]

L=[0]*(10**5+1)
B=dict(Counter(A))
for k in B.keys():
    L[k]=B[k]
# print(L)

sum = 0
for k in B.keys():
    sum += k*B[k]
for i in range(q):
    x=Q[i][0]
    y=Q[i][1]
    if L[x]==0:
        print(sum)
        continue
    L[y]+=L[x]
    L[x]=0
    sum=0
    for k in B.keys():
        sum+=k*L[k]
    print(sum)