n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = [map(int, input().split()) for _ in range(q)]
b, c = [list(i) for i in zip(*bc)]


ans = sum(a)
for i in range(q):
  dif = c[i] - b[i]
  ans += dif * a.count(b[i])
  a = [c[i] if j == b[i] else j for j in a]
  print(ans)