import collections
import numpy as np

n=int(input())
A = np.array(list((map(int,input().split()))))
Q=int(input())
B=[0]*Q
C=[0]*Q
for i in range(Q):
  B[i], C[i]=map(int,input().split())
#print(A,B,C)

#c = collections.Counter(A)
#values, counts = map(np.array,zip(*c.most_common()))
#print(values,counts)


for i in range(Q):
  A=np.where(A==B[i],C[i],A)
  print(np.sum(A))
  
  