# -*- coding: utf-8 -*-
#数を取得
count = int(input())
seq = list(map(int, input().split()))
repeat = int(input())
#置換する
for i in range(0, repeat):
  replace = list(map(int, input().split()))
  for i, value in enumerate(seq):
    if value == replace[0]:
      seq[i] = replace[1]
  print(sum(seq))
