N = int(input())
A = [int(x) for x in input().split()]
Q = int(input())
A_replace = A
for i in range(Q):
  b,c = (int(x) for x in input().split())
#  print(b,c,A)
  A_replace = [c if i == b else i for i in A_replace]
#  print(A_replace)
  print(sum(A_replace))