#include<iostream>
#include<list>
using namespace std;

class Node{
public:
	string word;
	list <int> page;
	Node(string w,list<int> p){
		word=w;page=p;
	}
	bool operator < ( const Node &o ) const{
		return word > o.word;
	}
};
typedef list<Node> DB;
DB db;
list<Node>::iterator
getKey(string word){
	list<Node>::iterator it=db.begin();
	for(;it!=db.end();it++){
		if(it->word==word)return it;
	}
	return it;
}

list<Node>::iterator
getInsertPointWord(string word){
	list<Node>::iterator it=db.begin();
	for(;it!=db.end();it++){
		if(word < it->word)return it;
	}
	return it;
}
list<int>::iterator
getInsertPointNum(int num,list<Node>::iterator it){
	list<int>::iterator itp=it->page.begin();
	for(;itp!=it->page.end();itp++){
		if(num < *itp)return itp;
	}
	return itp;
}

void print(){
	list<Node>::iterator it=db.begin();
	for(;it!=db.end();it++){
		cout<<it->word<<endl;
		list<int>::iterator itp=it->page.begin();

		for(int i=0;itp!=it->page.end();itp++,i++){
			if(i)cout<<" ";
			cout<<*itp;
		}
		cout<<endl;
	}
}
int
main(){
	string word;
	int page;
	for(;cin>>word;){
		cin>>page;
		list<Node>::iterator it=getKey(word);
		if(it==db.end()){
			it=getInsertPointWord(word);
			list <int> pages;pages.push_back(page);
			db.insert(it,Node(word,pages));
		}
		else{
			list<int>::iterator itp=getInsertPointNum(page,it);
			it->page.insert(itp,page);
		}
	}
	print();
	return 0;
}