import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
Q = int(input())
B = []
C = []
for i in range(Q):
  b, c = map(int, input().split())
  B.append(b)
  C.append(c)
for i in range(Q):
  A = np.where(A==B[i], C[i], A)
  print(np.sum(A))