import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;
import std.bigint;
import std.container;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}

void main() {
	auto N = readInt();
	while(true) {
		alias t = Tuple!(int, int, string);
		t[] s;
		foreach(i; 0..N) {
			auto l = readln().strip().split();
			s ~= t(-(to!int(l[1])*3+to!int(l[3])), i, l[0]);
		}
		s.sort();
		foreach(ss; s) {
			writeln(ss[2], ",", -ss[0]);
		}

		N = readInt();
		if(N == 0) {
			break;
		}
		writeln();
	}
}