#include <iostream>
#include <algorithm>
struct team{
	std::string name;
	float point;
};

bool tsort(const team& a,const team& b){
	return a.point > b.point;
}

int main(){
	int n;
	while(std::cin>>n,n){
		team all[10];
		for(int i = 0;i < n;i++){
			std::string name;
			int w,d,l;
			std::cin>>name>>w>>l>>d;
			team t = {name,(float)(w*3+d*1) + 0.1 * (n - i)};
			all[i] = t;
		}
		std::sort(all,all+n,tsort);
		for(int i = 0;i < n;i++){
			std::cout<<all[i].name<<","<<(int)all[i].point<<std::endl;
		}
		std::cout<<std::endl;
	}
}