#include<iostream>
#include<string>
#include<list>
using namespace std;
typedef struct type{
int gender;
string s;
}match;
int main(){
int i,j,k;
int n;cin>>n;
match t;
list<match>list_t;
while(n--){
cin>>t.gender>>t.s;
list_t.push_back(t);
}
list<match>::iterator it1,it2;
for(it1=list_t.begin();;){
for(it2=list_t.end(),it2--;;){
if(it1->gender!=it2->gender){
cout<<it1->s<<' '<<it2->s<<endl;
list_t.erase(it1++);
list_t.erase(it2--);
break;
}
else --it2;
}
if(list_t.empty())
break;
}
return 0;
}
#include<string>
#include<list>
using namespace std;
typedef struct type{
int gender;
string s;
}match;
int main(){
int i,j,k;
int n;cin>>n;
match t;
list<match>list_t;
while(n--){
cin>>t.gender>>t.s;
list_t.push_back(t);
}
list<match>::iterator it1,it2;
for(it1=list_t.begin();;){
for(it2=list_t.end(),it2--;;){
if(it1->gender!=it2->gender){
cout<<it1->s<<' '<<it2->s<<endl;
list_t.erase(it1++);
list_t.erase(it2--);
break;
}
else --it2;
}
if(list_t.empty())
break;
}
return 0;
}

