#include<map>
#include<string>
#include<vector>
#include<iostream>
#include<algorithm>
#include<functional>

#define	score	first
#define	id		second

using namespace std;

typedef	pair<int,int>	pii;

int main()
{
	int n;

	while(cin>>n,n){
		map<string,pii> mp;
		string name;
		int w,d,l;

		for(int i=0;i<n;i++){
			cin>>name>>w>>l>>d;
			mp[name].score=3*w+d;
			mp[name].id=i;
		}

		vector< pair<pii,string> > v;
		map<string,pii>::iterator it;
		for(it=mp.begin();it!=mp.end();it++){
			v.push_back(make_pair(it->second,it->first));
		}

		sort(v.begin(),v.end(),greater< pair<pii,string> >());

		for(int i=0;i<v.size();i++){
			cout<<v[i].second<<","<<v[i].first.score<<endl;
		}
		cout<<endl;
	}

	return 0;
}