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

int main()
{
	pair <string, int> score[10];
	int n, w, l, d;
	while (1)
	{
		int flg = 0;
		cin >> n;
		if (n == 0) break;
		if (flg != 0) cout << endl;

		for (int i = 0; i < n; i++)
		{
			cin >> score[i].first >> w >> l >> d;
			score[i].second = w * 3 + d;
		}
		flg++;

		sort(score, score + n);
		reverse(score, score + n);
		for (int i = 0; i < n; i++)
		{
			cout << score[i].first << "," << score[i].second << endl;
		}
	}

	return 0;
}