#include <stdio.h>
#include <math.h>
#include <string.h>
int main() {
int n;
scanf("%d", &n);
struct student {
char name[20];
int score[3];
} stu[1000];
int i, j, k, l;
for (i = 0; i < n; i++) {
scanf("%s%d%d%d", stu[i].name, &stu[i].score[0], &stu[i].score[1], &stu[i].score[2]);
}
for (i = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
if (abs(stu[i].score[0] - stu[j].score[0]) <= 5
&& abs(stu[i].score[1] - stu[j].score[1]) <= 5
&& abs(stu[i].score[2] - stu[j].score[2]) <= 5
&& abs((stu[i].score[0] + stu[i].score[1] + stu[i].score[2]
- stu[j].score[0] - stu[j].score[1] - stu[j].score[2]) <= 10)) {
for (k = 0; k < strlen(stu[i].name) && strlen(stu[j].name); k++) {
if (stu[i].name[k] < stu[j].name[k]) {
printf("%s %s\n", stu[i].name, stu[j].name);
break;
} else if (stu[i].name[k] > stu[j].name[k]) {
{
printf("%s %s\n", stu[j].name, stu[i].name);
break;
}
}
}
}
}
}
return 0;
}