pm = {}

while (s = gets) != "\n"
  (n, c) = s.chomp.split(/,/).map(&:to_i)
  pm[n] = [] if !pm.key?(n)
  pm[n].push(c)
end

tm = {}

while (s = gets) != "\n"
  (n, c) = s.chomp.split(/,/).map(&:to_i)
  tm[n] = [] if !tm.key?(n)
  tm[n].push(c)
end