n = gets.chomp.to_i
a = gets.chomp.split(" ").map { |e|e.to_i  }
q = gets.chomp.to_i
ans = []
q.times do |i|
  b, c = gets.chomp.split(" ").map { |e|e.to_i  }
  sum = 0
  for i in 0..a.count - 1 do
    if a[i] == b
      a[i] = c
    end
  end
  ans << a.sum
end

puts ans
