#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(void){
        for(;;){

        int n,q=0;
        cin>>n;
        if(n==0)break;
        int w[10],l[10],d[10];
        int p[10];

        char team[10][20];


        for(int i=0;i<n;i++){
            scanf("%s%d%d%d",team[i],&w[i],&l[i],&d[i]);
            p[i]=w[i]*3+d[i];
        }
        for(int i=3*n;i>=0;i--){
            for(int j=0;j<n;j++){
                if(p[j]==i){
                    cout<<team[j]<<","<<p[j]<<endl;
                    q++;
                }
            }

        }

        cout<<endl;
        }
	return 0;
}