program main
read*,n

call sub1(n)
end program

subroutine sub1(n)
integer(8)::a(1:n)
integer(8)::b(1:200000)
integer(8)::c(1:200000)
integer(4)::isum

read*,(a(j),j=1,n)
read*,iq

do i=1,iq
read*,b(i),c(i)
end do

isum=0
do j=1,iq
 do k=1,n
  if(a(k)==b(j))then
  a(k)=c(j)
  end if
  isum=isum+a(k)
 end do
 print*,isum
 isum=0
end do
end subroutine