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

int main(){
  int n;
  while(cin >> n){
    if(n == 0) break;
    multimap<int, string> ranking;
    for(int i = 0; i < n; i++){
      string  country;
      int win, lose, draw;
      cin >> country >> win >> lose >> draw;
      int point = win * 3 + lose * 0 + draw * 1;
      ranking.insert(make_pair(point, country));
    }

    for(multimap<int, string>::reverse_iterator ite = ranking.rbegin(); ite != ranking.rend(); ite++){
      cout << (*ite).second << ',' << (*ite).first << endl;
    }
  }

  return 0;
}