#include <iostream>
#include <algorithm>
using namespace std;
class pingwei{
public:
void create (){
cin>>this->name;
for(int y=0;y<7;y++){
cin>>this->score[y];
}
sort(this->score,this->score+7);
this->max=this->score[6];
this->min=this->score[0];
int sum1=0;
for(int y=0;y<7;y++){
sum1+=score[y];
}
this->sum=sum1-this->max-this->min;
}
void show (){
cout<<this->name;
cout<<" "<<this->sum<<endl;
}
char name [20];
int score[7];
int min,max;
int sum;
};
bool compare_function1(const pingwei &a,const pingwei &b)
{
return a.sum > b.sum;
}
int main (){
int u=0;
cin>>u;
pingwei *a=new pingwei [u];
for(int y=0;y<u;y++){
a[y].create();
}
sort(a,a+u,compare_function1);
for(int y=0;y<u;y++){
a[y].show();
}
return 0;
}