N = int(input())
A = [int(i) for i in input().split()]

Q = int(input())
s = sum(A)
for i in range(Q):
  b, c = map(int, input().split())
  delta = c - b
  count = 0
  for i in range(len(A)):
    if A[i] == b:
      A[i] = c
      count += 1
  s += count * delta
  print(s)