import collections

n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = [list(map(int, input().split())) for _ in range(q)]
ans = []
count = collections.Counter(a)
for i in range(q):
  total = 0
  num = count[bc[i][0]]
  count[bc[i][0]] = 0
  count[bc[i][1]] += num
  for key, value in zip(count.keys(), count.values()):
    total += int(key) * int(value)
  ans.append(total)

for out in ans:
  print(out)