N = int(input())
A = [int(x) for x in input().split()]
Q = int(input())
BC = [[int(x) for x in input().split()]for i in range(Q)]

Sum = sum(A)
for i in range(Q):
  b = BC[i][0]
  c = BC[i][1]
  Sum += (c-b)*A.count(b)
  print(Sum)
  A = [c if i == b else i for i in A]
