#include<iostream>
#include<cmath>
using namespace std;
struct Student {
string name;
int a, b, c;
}student[1000];
bool is(int x,int y) {
if (abs(x - y) <= 5) return 1;
return 0;
}
int main() {
int n, b[1000];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> student[i].name >> student[i].a >> student[i].b >> student[i].c;
b[i] = student[i].a + student[i].b + student[i].c;
}
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (is(student[i].a, student[j].a) && is(student[i].b, student[j].b) && is(student[i].c, student[j].c) && abs(b[i] - b[j] <= 10)) {
cout << student[i].name << " " << student[j].name << endl;
}
}
}
return 0;
}