#include<iostream>
#include<map>
#include<string>
using namespace std;

int main() {
	string c;
	int w, l, d;
	int n;
	int x = 0;
	while (cin >> n, n) {
		if (x >= 1) { cout << endl; }
		map<string, int>m;
		map<string, int>::reverse_iterator pm;
		for (int i = 0;i < n;i++) {
			cin >> c >> w >> l >> d;
			m[c] = w * 3 + d;
		}

		pm = m.rbegin();
		while(pm!=m.rend()){
			cout << pm->first << ',' << pm->second << endl;
			pm++;
		}
		x++;
	}
	return 0;
}