index = Hash.new{|index,key| index[key] = []}
while line = gets do
  word,page=line.split
  page=page.to_i
  index[word]<<page
end
 
index.each{|key,value|
  value.sort!
}
 
words=index.keys.sort!
words.each{|key|
  puts key
  puts index[key].join(" ")
}