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)]
# print(Q)

B=dict(Counter(A))
# print(B)

sum = 0
for k in B.keys():
    sum += k*B[k]
# print(B[2])
for i in range(q):
    x=Q[i][0]
    y=Q[i][1]
    if x not in B:
        print(sum)
        continue
    else:
        v = B[x]
        if y in B:
            B[y] += v
        else:
            B[y]=v
        del B[x]
        sum = 0
        for k in B.keys():
            sum += k*B[k]
        print(sum)
