index_list = {}

while line = gets
  word, page = line.split
  
  index_list[word] = [] if index_list[word].nil?
  index_list[word] << page.to_i
end

index_list.sort_by { |k, _| k }.each { |k, v| puts [k, v.sort.join(" ")] }