#include<iostream>
using namespace std;
int main(){
int n,x,i,j,k,id[101]={0},math[101]={0},english[101]={0},z[101]={0};
cin>>n;
for(i=1;i<=n;i++){
cin>>id[i]>>math[i]>>english[i];
z[i]=math[i]+english[i];
}
for(i=1;i<=n-1;i++){
for(j=i+1;j<=n;j++){
if(z[j]>z[i]){
swap(z[i],z[j]);
swap(id[i],id[j]);
swap(math[i],math[j]);
swap(english[i],english[j]);
}
}
}
for(k=2;k<=n;k++){
i=k;
while(z[i]==z[i-1]&&i>1){
if(math[i]>math[i-1]){
swap(z[i],z[i-1]);
swap(id[i],id[i-1]);
swap(math[i],math[i-1]);
swap(english[i],english[i-1]);
}
i--;
}
i=k;
while(z[i]==z[i-1]&&math[i]==math[i-1]&&i>1){
if(id[i]<id[i-1]){
swap(z[i],z[i-1]);
swap(id[i],id[i-1]);
swap(math[i],math[i-1]);
swap(english[i],english[i-1]);
}
i--;
}
}
for(i=1;i<=n;i++){
cout<<id[i]<<" "<<math[i]<<" "<<english[i]<<" "<<z[i]<<endl;
}
}