#include <iostream>
#include <cstdio>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		if(!n)break;
		vector<pair<int,string> > teams;
		for(int i=0,w,l,d;i<n;++i){
			string team;
			cin>>team>>w>>l>>d;
			teams.push_back(make_pair(w*3+d*1,team));
		}
		stable_sort(teams.begin(),teams.end());
		for(vector<pair<int,string> >::reverse_iterator it=teams.rbegin();it!=teams.rend();++it) printf("%s,%d\n",(*it).second.c_str(),(*it).first);
	}
	return 0;
}