#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;
    while(cin>>n,n){
        string str;
        int W,L,D;
        vector<pii>V;
        while(n--){
            cin>>str>>W>>L>>D;
            V.push_back(pii(W*3+D,str));
        }
        stable_sort(V.begin(),V.end(),greater<pii>());
        for(int i=0;i<V.size();i++){
            cout<<V[i].S<<","<<V[i].F<<endl;
        }
    }
}