index = Hash.new { |hash, key| hash[key] = [] }

loop do
  item, page = gets.chomp.split(' ')
  break if item == nil
  index[item] << page.to_i
end

index.sort.each do | key, value|
  puts key
  puts value.sort.join(" ")
end