#include<iostream>
using namespace std;
#include<math.h>
class student
{
public:
string name;
int cn;
int math;
int en;
int sum = cn + math + en;
};
student st[1005];
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> st[i].name >> st[i].cn >> st[i].math >> st[i].en;
for (int i = 1; i <= n-1; i++)
{
for (int j = i + 1; j <= n; j++)
{
if (
abs(st[i].cn-st[j].cn)<=5&&
abs(st[i].math-st[j].math)<=5&&
abs(st[i].en-st[j].en)<=5&&
abs(st[i].sum-st[j].sum)<=10
)
cout << st[i].name << " " << st[j].name << endl;
}
}
return 0;
}