#include<iostream>
#include<algorithm>
using namespace std;
int n;
struct node{
int no,c=0,m=0,e=0,total=0;
};
node a[600],c;
bool cmp(node x,node y) {
if(x.total>y.total)return true;
else if(x.total==y.total) {
if(x.c>y.c||x.e>y.e||x.m>y.m) return true;
else return false;
}
else return false;
}
int main() {
cin>>n;
for(int i=0;i<n;i++) {
cin>>a[i].c>>a[i].m>>a[i].e;
a[i].no=i+1;
a[i].total=a[i].c+a[i].m+a[i].e;
}
sort(a,a+n,cmp);
for(int i=0;i<5;i++) {
cout<<a[i].no<<" "<<a[i].total<<endl;
}
return 0;
}