#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
struct node{
int id,globalscore,chinese,math,english;
}a[310];
bool cmp(node x,node y){
if(x.globalscorey.globalscore){
if(x.chinesey.chinese)return x.id<y.id;
else return x.chinese>y.chinese;
}
else return x.globalscore>y.globalscore;
}
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
a[i].id=i;
cin>>a[i].chinese>>a[i].math>>a[i].english;
a[i].globalscore=a[i].chinese+a[i].math+a[i].english;
}sort(a+1,a+n+1,cmp);
for(int i=1;i<=5;i++){
cout<<a[i].id<<' '<<a[i].globalscore<<endl;
}
return 0;
}