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

using namespace std;

int main()
{
	int N, C = 0, X, Y, Z;

	while (true)
	{
		cin >> N;

		if (N == 0) { break; }

		if (C++) { cout << endl; }

		vector<pair<int, string> > R(N);

		for (int i = 0; i < N; i++)
		{
			cin >> R[i].second >> X >> Y >> Z;

			R[i].first = X * 3 + Z;
		}

		for (int i = 0; i < N; i++)
		{
			for (int j = i + 1; j < N; j++)
			{
				if (R[i].first < R[j].first)
				{
					swap(R[i], R[j]);
				}
			}
		}

		for (int i = 0; i < N; i++)
		{
			cout << R[i].second << ',' << R[i].first << endl;
		}
	}

	return 0;
}