#include<iostream>
#include<algorithm>
#include<queue>
#include<string>
#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;
        priority_queue<pii>Q;
        while(n--){
            cin>>str>>W>>L>>D;
            Q.push(pii(W*3+D,str));
        }
        while(!Q.empty()){
            pii p=Q.top();Q.pop();
            cout<<p.S<<","<<p.F<<endl;
        }
    }
}