#include<stdio.h>
#include<memory.h>
#include<iostream>
#include<string>
#include<map>
using namespace std;
int main(){
string a,b;
string c;
multimap<string,string>authors;
typedef multimap<string,string>::size_type sz_type;
while(cin>>a>>b){//输入键值和一实例;
authors.insert(make_pair(a,b));
sz_type entries = authors.count(a);
multimap<string,string>::iterator iter = authors.find(a);
for(sz_type i=0;i!=entries;i++,iter++){
cout << iter->second << endl;
}
cin>>b;//删除某个实例;
multimap<string,string>::iterator it = authors.find(a);
for(sz_type j=0;j!=entries;j++,it++){
cout<< it->second << endl;
if(it->second==b){
authors.erase(it);//it指针被删除;
break;
}
}
}
return 0;
}