import std.stdio;
import std.array;
import std.string;

void main(){
	string str;
	int n, w, l, d;
	bool f = true;
	while (readf("%d\n", &n), n) {
		if (f) f = false;
		else writeln();
		int[string] score;
		string[] s;
		for (int i = 0; i < n; i++) {
			readf("%s %d %d %d\n", &str, &w, &l, &d);
			score[str] = w*3 + d;
			for (int j = cast(int)s.length-1; true; j--) {
				if (j == -1 || score[s[j]] >= score[str]) {
					s.insert(j+1, str);
					break;
				}
			}
		}
		foreach (hoge; s) writeln(hoge, ",", score[hoge]);
	}
}