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}))

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

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