#include<bits/stdc++.h>
using namespace std;

typedef struct{
  string team;
  int win;
  int lose;
  int drow;
  int point;
}much;
  
int main(){
  while(1){
  much x[11],smp;
  int n;
  cin >> n;
  if(n == 0)break;
  for(int i=0;i<n;i++){
    cin >> x[i].team >> x[i].win >> x[i].lose >> x[i].drow;
  }
  for(int i=0;i<n;i++){
    x[i].point = x[i].win*3 + x[i].drow;
  }
  for(int i=0;i<n;i++){
    for(int j=i;j<n;j++){
      if(x[i].point < x[j].point){
	smp = x[i];
	x[i] = x[j];
	x[j] = smp;
      }
    }
  }
  for(int i=0;i<n;i++){
    cout << x[i].team << "," << x[i].point << endl <<endl;;
  }
}
}