#include<bits/stdc++.h>
using namespace std;
const int N = 1e3;
struct student
{
string name;
int chinese;
int math;
int english;
};
student stu[N];
bool judge(student a, student b)
{
if (abs(a.chinese - b.chinese) <= 5 && abs(a.math - b.math <= 5) && abs(a.english - b.english <= 5) && abs(a.chinese + a.math + a.english - b.chinese - b.math - b.english) <= 10)
return true;
else
return false;
}
int main()
{
int n, i, j;
cin >> n;
for (i = 0; i < n; i++)
cin >> stu[i].name >> stu[i].chinese >> stu[i].math >> stu[i].english;
for (i = 0; i < n; i++)
{
for (j = i + 1; j < n; j++)
{
if (judge(stu[i], stu[j]) == true)
cout << stu[i].name << " " << stu[j].name << endl;
}
}
return 0;
}