#include<bits/stdc++.h>
using namespace std;
long long n;
struct st{
int xh,yw,sx,yy,zo;
}a[310];
bool cmp(st x,st y){
if(x.zo>y.zo){
return 1;
}else{
if(x.yw>y.yw){
return 1;
}else{
if(x.xh<y.xh){
return 1;
}
}
}
return 0;
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i].yw>>a[i].sx>>a[i].yy;
a[i].xh=i;
a[i].zo=a[i].yw+a[i].sx+a[i].yy;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=5;i++){
cout<<a[i].xh<<" "<<a[i].zo<<endl;
}
return 0;
}