# -*- 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()))
  seq = [replace[1] if l == replace[0] else l for l in seq]
  print(sum(seq))
