N = int(input())
A = list(map(int, input().split()))
Q = int(input())
L = []
for i in range(Q):
  L.append(list(map(int, input().split())))

S = sum(A)
for i in range(Q):
  a = A.count(L[i][0])
  S += a*(L[i][1]-L[i][0])
  print(S)
  A = [L[i][1] if j == L[i][0] else j for j in A]