
n = int(input())
a = list(map(int, input().split()))
q = int(input())

result = a
sum = sum(result)
l = []
for i in range(q):
  b, c = map(int, input().split())

  count = 0
  # result = [c if j == b else j for j in result]

  # l.append(sum(result))
  for j in range(len(result)):
    if result[j] == b:
      count = count+ 1
      result[j] = c
  sum += count * (c-b)
  print(sum)
#   l.append(sum)

# for i in l:
#   print(i)