#include<bits/stdc++.h>
#define maxx 114514
using namespace std;
struct jxj{
long long num,f,f1;
}a[maxx];
bool cmp(jxj x,jxj y){
if(x.f==y.f){
return x.f1>y.f1;
}
else return x.f>y.f;
}
int main(){
long long n,x,b,c;
cin>>n;
for(int i=1;i<=n;i++){
a[i].num=i;
cin>>x>>b>>c;
a[i].f=x+b+c;
a[i].f1=x;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=5;i++){
cout<<a[i].num<<" "<<a[i].f;
cout<<endl;
}
return 0;
}