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

pair<int, string> pa[10];

int main() {
	int N,ff=0;
	while (cin >> N, N) {
		if (ff == 1)cout << endl;
		for (int i = 0; i < N; i++) {
			cin >> pa[i].second;
			int w, l, d;
			cin >> w >> l >> d;
			pa[i].first = w * 3 + d;

		}

		sort(pa, pa + N );

		for (int i = N - 1; i >= 0; i--) {
			cout << pa[i].second << "," << pa[i].first << endl;
		}
		ff = 1;

	}

}
