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
  cnt = 0
  if b in list_A:
    flag = True
    while flag:
      try:
        Index = list_A.index(b)
        list_A[Index] = c
        cnt += 1
      except ValueError:
        flag = False
  else:
    pass
  dif = cnt*(int(c) - int(b))
  SUM += dif
  print(SUM)