import std.stdio;
import std.algorithm;
import std.string;
import std.functional;
import std.array;
import std.conv;
import std.math;
import std.typecons;
import std.regex;
import std.range;

Tuple!(int,string)[] insort(Tuple!(int,string)[] arr){
    for(int i=1;i<arr.length;i++){
	int j = i;
	while(arr[j][0] > arr[j-1][0]){
	    swap(arr[j],arr[j-1]);
	    j--;
	    if(j==0) break;
	}
    }
    return arr;
}

void main(){

    int n =readln().chomp().to!int;
    while(true){
	Tuple!(int,string)[] list;
	for(int i=0;i<n;i++){
	    auto s = readln().split();
	    list ~= tuple( to!int(s[1])*3 + to!int(s[3]),s[0]);
	}
	list = insort(list);
	foreach(i;list) writeln(i[1],",",i[0]);
	n =readln().chomp().to!int;
	if(n==0)break;
	writeln();
    }

}