index_hash = {}
while input_lines = gets.chomp
    index_text, index_pages = input_lines.split(' ')

    if index_hash.key?(index_text)
        index_hash[index_text] << index_pages
    else
        index_hash[index_text] = [index_pages]
    end
end

index_hash_sort = index_hash.sort
index_hash_sort.length.times do |i|
    puts index_hash_sort[i][0]
    puts index_hash_sort[i][1].map!(&:to_i).sort.join(' ')
end