n = int(input())
A = tuple(map(int, input().split()))
Q = int(input())
Bs = [tuple(tuple(map(int, input().split()))) for i in range(Q)]
X = [0]
for i in range(1, 100001):
  X.append(A.count(i))
S = sum(A)
for B in Bs:
  S += X[B[0]]*(B[1]-B[0])
  X[B[1]] += X[B[0]]
  X[B[0]] = 0
  print(S)