#include<iostream>
#include<functional>
#include<string>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef pair<string,int> P;
int main(){
	string s,temp;
	int x;
	priority_queue<int,vector<int>,greater<int>()> que;
	multimap<string,int> box;
	while(cin>>s>>x,x)
		box.insert(P(s,x));
	box.insert(P("zzzzzzz",0));
	multimap<string,int>::iterator ite;
	for(ite=box.begin();ite->second!=0;){
		temp=ite->first;
		que.push(ite->second);
		ite++;
		while(ite->first==temp){
			que.push(ite->second);
			ite++;
		}
		cout<<temp<<endl;
		cout<<que.top();
		que.pop();
		while(!que.empty()){
			cout<<' '<<que.top();
			que.pop();
		}
		cout<<endl;
	}
	return 0;
}