
import collections
n = int(input())
a = list(map(int, input().split()))
q = int(input())
dic = collections.Counter(a)
ans = [sum(a)]
for i in range(q):
  b, c = map(int, input().split())
  if b in dic and c in dic:
    ans.append(ans[-1] - b * dic[b] + c * dic[c])
    dic[c] += dic[b]
    dic.pop(b)
  elif b in dic and c not in dic:
    dic[c] = dic[b]
    ans.append(ans[-1] - b * dic[b] + c * dic[c])
    dic.pop(b)
  else:
    ans.append(ans[-1])
for i in range(1, q + 1):
  print(ans[i])