import numpy

tmp=input()
list=input().split(" ")
array=numpy.zeros(len(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(" ")
  if int(b[0]) in array:
    array=numpy.where(array==int(b[0]),int(b[1]),array)
#    for j in pos:
#      array[j]=int(b[1])
    sum=numpy.sum(array)
    print(sum)
  else:
    sum=numpy.sum(array)
    print(sum)
  