program sample
    implicit none
  
    integer(8) :: i,j,m,n,k,q,b,c
    
    integer(8),allocatable :: a(:)
  
    read(*,*) n
    allocate(a(n))
    read(*,*)a
    read(*,*)q
    !call msort(a)

    do i=1,q
        read(*,*)b,c
        do j=1,n
            if(a(i)==b)then
                a(i)=c
            end if
        end do
    end do
    
    write(*,*)sum(a)
    stop
end program sample
  

