#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <vector>
#include <algorithm>

#define int64 long long int

using namespace std;

int main()
{
	int page, c, flag;
	string buf, word[1001];
	string index[100];
	
	c = 0;
	while(cin >> buf >> page){
		if(index[0].empty()) {
			index[0] = buf;
			c++;
		} else {
			flag = 0;
			for(int i=0; i<c; i++){
				if(index[i] == buf){
					flag = 1;
					break;
				}
			}
			if(flag == 0){
				index[c] = buf;
				c++;
			}
		}
		word[page] = buf;
	}

	for(int i=0; i<=c-2; i++){
		for(int j=c-2; j>=i; j--){
			if(index[j] > index[j+1]){
				buf = index[j];
				index[j] = index[j+1];
				index[j+1] = buf;
			}
		}
	}

	for(int i=0; i<c; i++){
		cout << index[i] << endl;
		flag = 0;
		for(int j=1; j<=1000; j++){
			if(index[i] == word[j]){
				if(flag == 1) cout << ' ';
				flag = 1;
				cout << j;
			}
		}
		cout << endl;
	}

	return 0;
}