import numpy

tmp=input()
list=input().split(" ")
list=[int(x) for x in list]
array=numpy.array(list,dtype=">i4")
#for i in range(len(list)):
#  array[i]=int(list[i])

a=int(input())#-1

for i in range(a):
  b=input().split(" ")
  array=numpy.where(array==int(b[0]),int(b[1]),array)
  sum=numpy.sum(array)
  print(sum)