#include <iostream>
#include <string>
#include <algorithm>

class WP {
public:
	std::string word;
	int page;
public:
	WP() {
		this->word = "";
		this->page = 0;
	}
	WP( std::string word, int page ) {
		this->word = word;
		this->page = page;
	}
	bool operator>=(const WP& rhs) {
		if (this->word.compare(rhs.word) > 0) return true;
		else if (this->word.compare(rhs.word) < 0) return false;
		else {
			return (this->page >= rhs.page);
		}
	}
	bool operator>(const WP& rhs) {
		if (this->word.compare(rhs.word) > 0) return true;
		else if (this->word.compare(rhs.word) < 0) return false;
		else {
			return (this->page > rhs.page);
		}
	}
	bool operator<=(const WP& rhs) {
		if (this->word.compare(rhs.word) < 0) return true;
		else if (this->word.compare(rhs.word) > 0) return false;
		else {
			return (this->page <= rhs.page);
		}
	}
	bool operator<(const WP& rhs) {
		if (this->word.compare(rhs.word) < 0) return true;
		else if (this->word.compare(rhs.word) > 0) return false;
		else {
			return (this->page < rhs.page);
		}
	}
	bool operator==(const WP& rhs) {
		if (this->word.compare(rhs.word) != 0) return false;
		else {
			return (this->page == rhs.page);
		}
	}
	bool operator!=(const WP& rhs) {
		if (this->word.compare(rhs.word) != 0) return true;
		else {
			return (this->page != rhs.page);
		}
	}
	~WP() {}
};

int main()
{
	WP words_list[100];
	std::string word;
	int page;
	int input_size = 0;
	while (std::cin >> word >> page) {
		words_list[input_size] = WP(word, page);
		input_size++;
	}
	
	std::sort(words_list, words_list + input_size);
	
	for (int i=0; i<input_size; i++) {
		std::cout << words_list[i].word << std::endl;
		std::cout << words_list[i].page;
		while (words_list[i].word == words_list[i+1].word) {
			i++;
			std::cout << " " << words_list[i].page;
		}
		std::cout << std::endl;
	}

	return 0;
}


