import std.stdio;
import std.algorithm;

class Team{
	string s;
	int n;
	int opCmp(Object o){
		Team t = cast(Team)o;
		return t.n - this.n;
	}
}
void main(){
	int n, w, l, d;
	readf("%d\n", &n);
	while (1) {
		Team[] team;
		for (int i = 0; i < n; i++) {
			Team t = new Team;
			readf("%s %d %d %d\n", &t.s, &w, &l, &d);
			t.n = w*3 + d;
			team ~= t;
		}
		team.sort;
		foreach (t; team) {
			writeln(t.s, ',', t.n);
		}
		readf("%d\n", &n);
		if (n == 0) break;
		writeln();
	}
}