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())
  ans = base + (c-b) * cnt[b]
  ANS.append(ans)
  cnt[c] += cnt[b]
  cnt[b] = 0
  base = ans

for i in ANS:
  print(i)