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.to_i
    else
        index_hash[index_text] = [index_pages.to_i]
    end
end

index_hash.sort.each do |key, val|
    puts key
    puts val.sort.join(' ')
end