#include<iostream>
#include<string>
using namespace std;
struct ren{
int c[3];
string m;
}a[10086],b;
int n,n1,z[2];
int bi(int x1,int x2){
if(x1>=x2&&x1-x2<=5){
return 1;
}
if(x1<x2&&x2-x1<=5){
return 1;
}
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i].m>>a[i].c[1]>>a[i].c[2]>>a[i].c[3];
}
for(int i=1;i<=n;i++){
b.m=a[i].m;
b.c[1]=a[i].c[1];
b.c[2]=a[i].c[2];
b.c[3]=a[i].c[3];
z[1]=(b.c[1]+b.c[2]+b.c[3]);
for(int i1=i+1;i1<=n;i1++){
if(i!=i1){
z[2]=(a[i1].c[1]+a[i1].c[2]+a[i1].c[3]);
if(z[1]>=z[2]&&z[1]-z[2]<=10)
{
for(int l=1;l<=3;l++){
n1+=bi(b.c[l],a[i1].c[l]);
}
if(n1==3){
if(i>i1){
cout<<b.m<<" "<<a[i1].m<<endl;
}
else{
cout<<a[i1].m<<" "<<b.m<<endl;
}
n1=0;
}
else{n1=0;
}
}
if(z[1]<z[2]&&z[2]-z[1]<=10)
{
for(int l=1;l<=3;l++){
n1+=bi(b.c[l],a[i1].c[l]);
}
if(n1==3){
if(i>i1){
cout<<b.m<<" "<<a[i1].m<<endl;
}
else{
cout<<a[i1].m<<" "<<b.m<<endl;
}
n1=0;
}
else{n1=0;
}
}
}
}
}
return 0;
}