indice = {}
while page_info = gets.strip
  break if page_info.empty?
  page_contents, page_number = page_info.split
  indice[page_contents] = [] unless indice.has_key?(page_contents)
  indice[page_contents] << page_number.to_i
end

indice.sort{ |(k1, v1), (k2, v2)| k1 <=> k2 }.each do |word, page_numbers|
  puts word
  puts page_numbers.sort.join(" ")
end