#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
	int n;
	int flg = 0;
	while(1){
        cin >> n;
        if(n == 0) break;
        if(flg == 1) cout << endl;
        flg = 1;
        char cou[30][20];
        int kati[20],make[20],hiki[20];
        int p[20];

        for(int i = 0; i < n; i++){
            cin >> cou[i] >> kati[i] >> make[i] >> hiki[i];
            p[i] = 3 * kati[i] + hiki[i];
        }
        for(int i = n * n; i >= 0; i--){
            for(int j = 0; j < n; j++){
                if(p[j] == i) cout << cou[j] << "," << p[j] << endl;
            }
        }
	}
	return 0;
}