data_hash = Hash.new([])

while data = gets do
  if data == nil
  	break
  end
  word, page = data.chomp.split
  data_hash[word] += [page.to_i]
end

data_hash.sort.each do |word, page|
  puts word
  puts page.sort.join(' ')
end