#include <iostream>
#include <map>
#include <set>
using namespace std;

typedef pair<int, string> P;
set<P> team;

int main(void){
  int n;
  while(cin >> n, n){
    for(int i = 0; i < n; i++){
      string tname;
      int w, l, d;
      cin >> tname >> w >> l >> d;
      pair<int, string> t;
      t.first = w * 3 + d;  t.second = tname;
      team.insert(t);
    }
    set<P>::reverse_iterator it;
    for(it = team.rbegin(); it != team.rend(); it++){
      cout << (*it).second << "," << (*it).first << endl;
    }
    cout << endl;
    team.clear();
  }
  return 0;
}