#include <bits/stdc++.h>
using namespace std;
struct student
{
string name;
int ch, ma, en;
};
bool isValid(student x, student y)
{
int sumx, sumy;
sumx = x.ch + x.ma + x.en;
sumy = y.ch + y.ma + y.en;
if (abs(x.ch - y.ch) <= 5 && abs(x.ma - y.ma <= 5)
&& abs(x.en - y.en) <= 5 && abs(sumx - sumy) <= 10)
{
return true;
}
return false;
}
int main()
{
int n;
cin >> n;
vector<student> stus(n);
for (int i = 0; i < n; i++)
cin >> stus[i].name >> stus[i].ch >> stus[i].ma >> stus[i].en;
for (int i = 0; i < n-1; ++i)
{
for (int j = i+1; j < n; ++j)
{
if (isValid(stus[i], stus[j]))
{
cout << stus[i].name << ' ' << stus[j].name << endl;
return 0;
}
}
}
return 0;
}