#include <iostream>
#include <cmath>
using namespace std;
int n;
struct stu {
string name;
int chi, mat, eng;
int sum;
}stus[1009];
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> stus[i].name
>> stus[i].chi
>> stus[i].mat
>> stus[i].eng;
stus[i].sum = stus[i].chi + stus[i].mat + stus[i].eng;
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (abs(stus[i].chi - stus[j].chi) <= 5 &&
abs(stus[i].mat - stus[j].mat) <= 5 &&
abs(stus[i].eng - stus[j].eng) <= 5 &&
abs(stus[i].sum - stus[j].sum) <= 10) {
if (stus[i].name < stus[j].name)
cout << stus[i].name << " " << stus[j].name << endl;
else
cout << stus[j].name << " " << stus[i].name << endl;
}
}
}
return 0;
}