n = int(input())
list_A = input().split()
q = int(input())
SUM = sum(map(int, list_A))
for i in range(q):
  b, c = input().split()
  dif = 0
  if b in list_A:
    num = list_A.count(b)
    list_A = [c if x == b else x for x in list_A]
    dif = num*(int(c) - int(b))
  else:
    pass
  SUM += dif
  print(SUM)