#include <stdio.h>
#include <stdlib.h>
typedef struct { int number, chinese, math, english, total; } STUDENT;
#define MAX_STUDENT 100
int compare ( const void * a , const void * b )
{
if ( ((const STUDENT *)a)->total != ((const STUDENT *)b)->total )
return ((const STUDENT *)b)->total - ((const STUDENT *)a)->total;
else if ( ((const STUDENT *)a)->chinese != ((const STUDENT *)b)->chinese )
return ((const STUDENT *)b)->chinese - ((const STUDENT *)a)->chinese;
else
return ((const STUDENT *)a)->number - ((const STUDENT *)b)->number;
}
int main (void)
{
int n;
int i;
STUDENT student[MAX_STUDENT];
scanf( "%d", &n );
for ( i = 0 ; i < n ; i ++ )
{
student[i].number = i + 1;
scanf("%d%d%d", &(student[i].chinese), &(student[i].math), &(student[i].english) );
student[i].total = student[i].chinese + student[i].math + student[i].english;
}
qsort( student, n, sizeof(student[0]), compare );
for ( i = 0 ; i < 5 ; i ++ )
printf( "%d %d\n", student[i].number, student[i].total );
return 0;
}