/#include<bits/stdc++.h>
using namespace std;
struct stu{
char name[200];
long long id;
long long a,b,c,s;
} student[100000];
bool cmp(stu a,stu b){
if(a.s!=b.s){
return a.s>b.s;
}
if(a.a!=b.a){
return a.a>b.a;
}
return a.id<b.id;
}
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>student[i].name>>student[i].a>>student[i].b>>student[i].c;
student[i].id=i;
student[i].s=student[i].a+student[i].b+student[i].c;
}
sort(student****tudent+n+1,cmp);
for(int i=1;i<=n;i++){
cout<<student[i].name<<" "<<student[i].s<<endl;
}
return 0;
}/