#include<iostream>
#include<cstring>
using namespace std;
struct student{
string name;
int a,b,c;
};
student people[1001];
int main(){
int n;
cin>>n;
for(int i = 1;i <= n;i++){
cin>>people[i].name>>people[i].a>>people[i].b>>people[i].c;
}
for(int i = 1;i < n;i++)
for(int j = i;j <= n;j++)
if(i != j)
if(abs(people[i].a - people[j].a) <= 5)
if(abs(people[i].b - people[j].b) <= 5)
if(abs((people[i].a + people[i].b + people[i].c) - (people[i].a + people[i].b + people[i].c)) <= 10)
if(abs(people[i].c - people[j].c) <= 5){
if(people[i].name < people[j].name)
cout<<people[i].name<<" "<<people[j].name<<endl;
else cout<<people[j].name<<" "<<people[i].name<<endl;
}
}