#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	int n;
	bool f=false;
	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,team));
		}
		stable_sort(teams.rbegin(),teams.rend());
		if(f)cout<<endl;
		else f=true;
		for(vector<pair<int,string> >::iterator it=teams.begin();it!=teams.end();++it) cout<<(*it).second<<","<<(*it).first<<"\n";
	}
	return 0;
}