#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;
    while(cin>>n,n){
        priority_queue<pair<int,string>, vector<pair<int,string> >, less<pair<int,string> > >p;
        while(n--){
            string s;
            int a,b,c;
            cin>>s>>a>>b>>c;
            p.push(make_pair(3*a+c, s));
        }
        while(p.size()){
            pair<int,string>r=p.top();
            p.pop();
            cout<<r.second<<","<<r.first<<endl;
        }
    }
}