#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define F first
#define S second
using namespace std;
typedef pair<int,string> pii;
int main(){
    int n;
    bool f=false;
    while(cin>>n,n){
        if(f)cout<<endl;
        string str;
        int W,L,D;
        vector<pii>V(n);
        for(int i=0;i<n;i++){
            cin>>str>>W>>L>>D;
            V[i]=pii(W*3+D,str);
        }
        stable_sort(V.rbegin(),V.rend());

        for(int i=0;i<V.size();i++){
            cout<<V[i].S<<","<<V[i].F<<endl;
        }
        f=true;
    }
}