#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

typedef pair<int, string> T;

int main()
{
    int n;
    bool fst = true;
    while(cin >> n && n) {
        if(fst) {
            fst = false;
        } else {
            cout << endl;
        }
        vector<T> vt;
        string name;
        int a,b,c;
        while(n--) {
            cin >> name >> a >> b >> c;
            vt.push_back(T(a * 3 + c, name));
        }
        
        stable_sort(vt.begin(), vt.end());
        for(int i = vt.size() - 1; i >= 0; i--) {
            cout << vt[i].second << "," << vt[i].first << endl;
        }
    }
}