#include<stdio.h>
#include<math.h>
#include<string.h>
int judge(int a, int b, int distance);
struct stu
{
int numble;
int ChineseScore;
int MathScore;
int EnglishScore;
int sum;
char name[];
};
struct stu score[2500];
struct cp
{
char name1[];
char name2[];
};
struct cp name[2000];
int main()
{
int N = 0;
int count = 0;
scanf("%d", &N);
for (int i = 0; i < N; i++)
{
scanf("%s%d%d%d", score[i].name,&score[i].ChineseScore,//输入名字
&score[i].MathScore, &score[i].EnglishScore);
score[i].sum = score[i].ChineseScore + score[i].MathScore + score[i].EnglishScore;
}
for (int i = 0; i < N; i++)
{
for (int j = i+1; j < N; j++)
{
int flag1 = 1,flag2=1,flag3=1,flag4=1;
flag1 = judge(score[i].ChineseScore, score[j].ChineseScore, 5);
flag2 = judge(score[i].MathScore, score[j].MathScore, 5);
flag3 = judge(score[i].EnglishScore, score[j].EnglishScore, 5);
flag4 = judge(score[i].sum, score[j].sum, 10);
if (flag1&&flag2&&flag3&&flag4)
{
if (strcmp(score.name[i],score.name[j])>0)
{
strcpy(cp.name1[count],score.name[i]);
strcpy(cp.name2[count],score.name[j]);
}
else if (strcmp(score.name[i],score.name[j])<0)
{
strcpy(cp.name2[count],score.name[i]);
strcpy(cp.name1[count],score.name[j]);
}
count++;
}
}
}
for(int i=0;i<count;i++)
{
printf("%s%s",cp.name1[i],cp.name2[i]);
}
return 0;
}
int judge(int a, int b, int distance)
{
int flag = 1;
if (abs(a - b) > distance)
flag = 0;
return flag;
}