from collections import Counter
n = int(input())
a = list(map(int, input().split()))

A = {}
for i in range(n):
  A = dict(Counter(A) + Counter({a[i]:1}))

ans = 0
for x in A.keys():
  ans += x * A[x]

q = int(input())
for i in range(q):
  b,c = list(map(int, input().split()))
  if b in A.keys():
    ans -= b * A[b]
    ans += c * A[b]
    A = dict(Counter(A) + Counter({c:A[b]}))
    A = dict(Counter(A) - Counter({b:A[b]}))
    print(ans)
    
    
