N = int(input())
A = list(map(int, input().split()))
Q = int(input())
lis = [0]* 10 ** 5
S = sum(A)

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