#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n;
    while(scanf("%d",&n),n){
        char team[11][21] = {{0}};
        int w[11],d[11],l[11];
        int to[11][2] = {0};

        //in
        for(int i = 0;i < n; i++){
            scanf("%s%d%d%d",team[i],&w[i],&l[i],&d[i]);
            to[i][0] = (w[i]*3)+d[i];
            to[i][1] = w[i];
        }
        //out
        for(int i = 0;i < n; i++){
            for(int j = 0;j < n; j++){
                if(to[i][0] > to[j][0]){
                    swap(to[i][0],to[j][0]);
                    swap(team[i],team[j]);
                }
                else if(to[i][0] == to[j][0]){
                    if(to[i][1] > to[j][1]){
                        swap(to[i][0],to[j][0]);
                        swap(team[i],team[j]);
                    }
                }
            }
        }
        for(int i = 0;i < n; i++)printf("%s,%d\n",team[i],to[i][0]);
    }
    return 0;
}