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

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

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

        while(!que.empty()){
            P p=que.top();que.pop();
            cout<<p.second<<","<<p.first<<endl;
        }
    }

    return 0;
}