N, M = gets.split.map(&:to_i) rating = Hash.new N.times do s, a = gets.chomp.split rating[s] = a.to_i end M.times do t, b = gets.chomp.split rating[t] = b.to_i end rating.sort_by { |name, _| name }.each do |name, rate| puts [name, rate].join(' ') end