#include <stdio.h>
#include <math.h>
typedef struct {
char name[9];
int yw;
int sx;
int yu;
int zf;
} cji;
int main(void) {
int n, i, j;
scanf("%d", &n);
cji txue[1001];
for (i = 0; i < n; i++) {
scanf("%s %d %d %d", txue[i].name, &txue[i].yw, &txue[i].sx, &txue[i].yu);
txue[i].zf = txue[i].sx + txue[i].yu + txue[i].yw;
}
for (i = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
if (abs(txue[i].yu - txue[j].yu) < 5 &&
abs(txue[i].sx - txue[j].sx) < 5 &&
abs(txue[i].yw - txue[j].yw) < 5 &&
abs(txue[i].zf - txue[j].zf) < 10) {
printf("%s %s\n", txue[i].name, txue[j].name);
}
}
}
return 0;
}