#include<iostream>
#include<map>
#include<string>
#include<vector>
using namespace std;
int main() {
map<string, vector<string>> name;
string last_name, first_name;
while (cin >> last_name >> first_name) {
name[last_name].push_back(first_name); //name[last_name]表示vector的元素
}
for (auto it = name.cbegin(); it != name.cend(); it++) {
for (auto i = it->second.cbegin(); i != it->second.cend(); i++) //it->second 表示vector的元素
cout <<it->first<<" "<< *i << " ";
cout << endl;
}
return 0;
}