#include <iostream>
#include <math.h>
using namespace std;
struct student {
string name;
int a, b, c;
};
bool canbe(student s1, student s2) {
if (abs(s1.a - s2.a) <= 5 && abs(s1.b - s2.b) <= 5 && abs(s1.c - s2.c) <= 5
&& abs(s1.a + s1.b + s1.c - s2.c - s2.b - s2.a) <= 10 )
return 1;
return 0;
}
student stu[1005];
string cp[1005][2];
int main() {
int n;
cin >> n;
int cp_p = 0;
for (int i = 0; i < n; i++) {
cin >> stu[i].name >> stu[i].a >> stu[i].b >> stu[i].c;
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (canbe(stu[i], stu[j])) {
if (stu[i].name < stu[j].name) {
cp[cp_p][0] = stu[i].name;
cp[cp_p][1] = stu[j].name;
} else {
cp[cp_p][0] = stu[j].name;
cp[cp_p][1] = stu[i].name;
}
cp_p++;
}
}
}
for (int i = 0; i < cp_p; i++) {
cout << cp[i][0] << " " << cp[i][1] << endl;
}
return 0;
}