#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
struct date{
    char cou[30];
    int kati;
    int make;
    int hiki;
    int ten;
    int num;
};
int main()
{
    int flg = 0;
	while(1){
        int n;
        cin >> n;
        if(n == 0) break;
        if(flg == 1) cout << endl;
        flg = 1;
	    date aoj[20];
        for(int i = 0; i < n; i++){
            cin >> aoj[i].cou >> aoj[i].kati >> aoj[i].make >> aoj[i].hiki;
            aoj[i].kati *= 3;
            aoj[i].make *= 0;
            aoj[i].num = i;
            aoj[i].ten = aoj[i].kati + aoj[i].make + aoj[i].hiki;
        }
        for(int i = 0; i < n; i++){
            for(int j = i; j < n; j++){
                if(aoj[i].ten < aoj[j].ten) swap(aoj[i],aoj[j]);
            }
        }

        for(int i = 0; i < n; i++){
            cout << aoj[i].cou << "," << aoj[i].ten << endl;
        }
	}
	return 0;
}