import numpy as np
N = int(input())
A = np.array(input().split(), dtype = int)
Q = int(input())
lis = [0]* 10 ** 5
S = sum(A)

for i in range(10 ** 5):
  lis[i] = np.count_nonzero(A == i + 1)
  
for _ in range(Q):
  B, C = map(int, input().split())
  S += (C - B) * lis[B - 1]
  print(S)
  lis[C - 1] += lis[B - 1]
  lis[B - 1] = 0
