import collections
N=int(input())
A=list(map(int,input().split()))
A=sorted(A)
Q=int(input())
B=[0]*Q;C=[0]*Q
for i in range(Q):
  B[i],C[i]=map(int,input().split())

#c = collections.Counter(A)
#print(c)

for i in range(Q):
  A = [C[i] if B[i]==A[j] else A[j] for j in range(N)]
#  print(A)
  print(sum(A))
#l_replace = [100 if i > 0 else i for i in l]  
#
#  print(C[i]-1,B[i]-1)
##  D[B[i]-1]=0
#  print(int(np.average(D, weights=W)))
  