import collections

n = map(int, input().split())
A = list(map(int, input().split()))
q = map(int, input().split())

cnt = collections.Counter(A)
ANS = []
base = sum(A)

for i in range(q):
    b, c = map(int, input().split())
    t = CNT[b]
    ans = base + (c - b) * t
    ANS.append(ans)
    CNT[c] += t
    CNT[b] = 0
    base = ans

for i in ANS:
    print(i)