#include <iostream>
#include <string>

using namespace std;

struct Team {
	string name;
	int score;
};

int main() {

	int n;

	while (cin >> n && n != 0) {

		Team *team = new Team[n];
		int w, l, d;

		for (int i = 0; i < n; i++) {

			cin >> team[i].name >> w >> l >> d;
			team[i].score = w * 3 + d * 1;


		}

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (team[i].score > team[j].score)
					swap(team[i], team[j]);
			}
		}

		for (int i = 0; i < n; i++)
			cout << team[i].name << "," << team[i].score << "\n";

	}


	return 0;

}


