#include<iostream>
#include<cmath>
#include<cstring>
using namespace std;
class student
{
public:
char name[9];
int chinese, english, math, total;
void stu(char n[], int c, int e, int m)
{
strcpy(name, n);
chinese = c; english = e; math = m; total = c + e + m;
}
};
int main()
{
int n;
cin >> n;
student s[1000];
for (int i = 0; i < n; i++)
{
char cc[20];
int c, e, m;
cin >> cc >> c >> e >> m;
s[i].stu(cc, c, e, m);
}
for (int i = 0; i < n - 1; i++)
for (int j = i + 1; j < n; j++)
{
if (fabs(s[i].chinese - s[j].chinese) <= 5 && fabs(s[i].english - s[j].english) <= 5 && fabs(s[i].math - s[j].math) <= 5 && fabs(s[i].total - s[j].total) <= 5)
{
cout << s[i].name << " " << s[j].name<<endl;
}
}
return 0;
}