import numpy as np

N=int(input())
A=list(map(int,input().split()))
Q=int(input())
ope=[]
for i in range(Q):
  ope.append(list(map(int,input().split())))
ope=np.array(ope)
A=np.array(A)

for b,c in ope:
  A[A==b]=c
  print(np.sum(A))
