#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<string>
#include<vector>
using namespace std;
typedef pair<int,string> P;
main(){
  vector<P> ar;
  P p;
  int n,a,b,c,f=0;
  string s;
  while(1){
    cin >> n;
    if(!n)break;
    if(f == 0){
      cout << endl;
      f = 1;
    }
    for(int i=0;i<n;i++){
      cin >> s >> a >> b >> c;
      p.first = (a*3) + (c*1);
      p.second = s;
      ar.push_back( p );
    }
    sort( ar.begin() , ar.end() , greater<P>());
    for(int i=0;i<n;i++){
      cout << ar[i].second << ',' << ar[i].first << endl;
    }
    ar.clear();
  }
}