import math
# from collections import Counter

# N = int(input()) # 1行, 単数
# arg = list(map(int, input().split())) # 1行, 配列
# D = Counter(arg) # 出現数カウント

# print('Yes')
# print('No')
# print()
import collections
N = int(input()) # 1行, 単数
A = list(map(int, input().split())) # 1行, 配列
Q = int(input()) # 1行, 単数
counter = collections.Counter(A)

while True:
  try:
    # ans = 0
    B,C = list(map(int, input().split())) # 1行, 配列
    # counter[C] = counter[C] + counter[B]
    # del counter[B]
    # for i in counter.keys():
    #   ans = ans + i * counter[i]
    A = [C if i == B else i for i in A]
    
    print(sum(A))
  except:
    break;