#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

struct P{
    string name;
    int win;
    int lose;
    int even;
    int total;
    static bool more (const P& left,const P& right){
        return left.total > right.total;
    }
};

int main(){
    int n;
    int fl=0;
    int cnt;
    while(1){
        cnt = 0;
        cin >> n;
        if(n == 0) break;
        if(fl == 1) cout << endl << endl;
        vector <P> data;
        P tmp;
        for(int i=0;i<n;i++){
            cin >> tmp.name >> tmp.win >> tmp.lose >> tmp.even;
            tmp.total = tmp.win*3 + tmp.even;
            data.push_back(tmp);
            cnt++;
        }
        sort(data.begin(),data.end(),P::more);
        for(int i=0;i<cnt;i++){
            if(i == cnt-1) cout << data[i].name << "," << data[i].total;
            else cout << data[i].name << "," << data[i].total << endl;
        }
        fl = 1;
    }
}