data_hash = {}
while line = gets
  word, index = line.split " "
  data_hash[word] ||= []
  data_hash[word] << index
end

data_hash.keys.sort.each do |key|
  puts key+"\n"
  puts data_hash[key].map(&:to_i).sort.join(" ") + "\n"
end