inputs = readlines
 
original_array = inputs[1].split(' ').map(&:to_i)
array = original_array
sum = array.sum

orders = inputs[3..-1]
 
orders.each do |o|
    order = o.split(' ').map(&:to_i)
    count = 0
    array.map! do |a|
        if a == order[0]
            s = order[1]
            count += 1
            
        else
            s = a 
        end
        s
    end

    dif = (order[1] - order[0]) * count
    sum += dif
    puts sum
end