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

num = []
for i in range(100001):
  num.append(a.count(i))

sum = sum(a)
for i in range(q):
  sum = sum + (c[i] - b[i]) * num[b[i]]
  print(sum)
  num[c[i]] += num[b[i]]
  num[b[i]] = 0