n = int(input())

a_list = list(map(int, input().split()))

q = int(input())
sum_s = sum(a_list)

for i in range(q):
  b, c = map(int, input().split())
  sum_s += (c - b)*a_list.count(b)
  a_list = [c if i == b else i for i in a_list]
  print(sum_s)
