N = int(input())
A = list(map(int,input().split()))
Q = int(input())

for i in range(Q):
  B_C = list(map(int,input().split()))
  B = B_C[0]
  C = B_C[1]
  A = [C if Ai == B else Ai for Ai in A]
  print(sum(A))