#include <iostream>
#include <algorithm>
#include <map>
#include <vector>

using namespace std;

int main()
{
    int n;

    while (cin >> n) {
        if (!n)
            break;
        vector< pair<int, string> > tourn;

        for (int i = 0; i < n; i++) {
            int win, los, ev;
            string str;
        
            cin >> str >> win >> los >> ev;
            pair<int, string> p(win * 2 + ev, str);
            tourn.push_back(p);
        }
        sort(tourn.rbegin(), tourn.rend());
        
        for (int i = 0; i < tourn.size(); i++)
            cout << tourn[i].second << ',' << tourn[i].first << endl;
        cout << endl;
    }

    return 0;
}