#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
typedef pair<int,string> P;

int main(){
    int n,w=-1,l,d;
    string s;
    vector<P> v;

    while(cin>>n,n){
        if(w!=-1) cout<<endl;
        for(int i=0;i<n;i++){
            cin>>s>>w>>l>>d;
            cin.ignore();
            v.push_back(P(3*w+d,s));
        }

        stable_sort(v.begin(),v.end(),greater<P>());

        for(auto p:v){
            cout<<p.second<<","<<p.first<<endl;
        }

        v.clear();
    }

    return 0;
}