import std.stdio;
import std.algorithm;

int[string] score;

void main(){
	string s;
	int n, w, l, d;
	while (readf("%d\n", &n), n) {
		foreach (key; score.keys) score.remove(key);
		for (int i = 0; i < n; i++) {
			readf("%s %d %d %d\n", &s, &w, &l, &d);
			score[s] = w*3 + d;
		}
		auto keys = sort!(comp, SwapStrategy.stable)(score.keys);
		foreach (key; keys) {
			writeln(key, ',', score[key]);
		}
		writeln();
	}
}

bool comp(string a, string b){
	return score[a] > score[b];
}