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

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