#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<cmath>
#include<set>
#include<stack>

using namespace std;

int main(){
    int n,l=0;
    while(cin>>n,n){
        if(l)cout<<endl;l++;
        vector<pair<int,string> >p;
        while(n--){
            string s;
            int a,b,c;
            cin>>s>>a>>b>>c;
            p.push_back(make_pair(3*a+c, s));
        }
        sort(p.begin(),p.end());
        for(int i=0;i<p.size();i++){
            cout<<p[i].second<<","<<p[i].first<<endl;
        }
    }
}