import std.stdio;

struct Team {
	string name;
	int score;
	int order;
	int opCmp(ref const Team t) const{
		return score != t.score ? (t.score - score) : (order - t.order); 
	}
}

void main(){
	string s;
	int n, w, l, d;
	bool f = true;
	while (readf("%d\n", &n), n) {
		if (f) f = false;
		else writeln();
		Team[] team;
		for (int i = 0; i < n; i++) {
			readf("%s %d %d %d\n", &s, &w, &l, &d);
			team ~= Team(s, w*3+d);
		}
		team.sort;
		foreach (t; team) writeln(t.name, ",", t.score);
	}
}