#include <iostream>
using namespace std;
  
struct data{
  
char name;
int win;
int lose;
int draw;
int score;
  
};
  
int main(){
  
int teamamo;
  
while(true){
  
cin>>teamamo;
  
if(teamamo==0)
break;
  
data teamdata[10];
data comp;
  
for(int i=0; i<teamamo; i++)
cin>>teamdata[i].name>>teamdata[i].win>>teamdata[i].lose>>teamdata[i].draw;
  
for(int i=0; i<teamamo; i++)
teamdata[i].score=teamdata[i].win*3+teamdata[i].draw;
  
for(int i=0; i<teamamo-1; i++){
  
if(teamdata[i].score<teamdata[i+1].score){
  
char fout; 
fout=teamdata[i].name;
teamdata[i].name=teamdata[i+1].name;
teamdata[i+1].name=fout;
  
int gout;
gout=teamdata[i].win;
teamdata[i].win=teamdata[i+1].win;
teamdata[i+1].win=gout;
  
gout=teamdata[i].lose;
teamdata[i].lose=teamdata[i+1].lose;
teamdata[i+1].lose=gout;
  
gout=teamdata[i].draw;
teamdata[i].draw=teamdata[i+1].draw;
teamdata[i+1].draw=gout;
  
gout=teamdata[i].score;
teamdata[i].score=teamdata[i+1].score;
teamdata[i+1].score=gout;
  
    }
  
  
   }
  
for(int i=0; i<teamamo; i++)
cout<<teamdata[i].name<<','<<teamdata[i].score<<endl;
  
  
 }
  
return 0;
  
}