#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;

struct W{
    string word;
    priority_queue<int> pq;
    bool operator < (const W& o) const {
        return word < o.word;
    }
};

W genW(string w, int p){
    W new_word;
    new_word.word = w;
    new_word.pq.push( -p );
    return new_word;
}

int main(){
    string w; int p;
    vector< W > ls;
    vector< W >::iterator it;
    while( cin >> w >> p ){
        it = ls.begin();
        for(; it != ls.end(); it++){
            if( it->word == w ){
                it->pq.push( -p );
                break;
            }
        }
        if( it == ls.end() ){
            ls.push_back( genW(w, p) );
        }
    }
    sort(ls.begin(), ls.end());
    for(it = ls.begin(); it!=ls.end(); it++){
        cout << it->word << endl;
        cout << -( it->pq.top() );
        it->pq.pop();
        while( !it->pq.empty() ){
            cout << ' ' << -( it->pq.top() );
            it->pq.pop();
        }
        cout << endl;
    }
    return 0;
}