#include<iostream>
#include<complex>
#include<cstring>
#include<sstream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<vector>
#include<string>
#include<deque>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<list>
#include<functional>
#include<algorithm>
#define rep(i,k) for(int i=0;i<k;i++)
using namespace std;
typedef pair<int,string> P;
int main(){
	int n,x,y,z,now=0;
	vector<P> tab;
	string s;
	while(cin>>n,n){
		if(now!=0)
		cout<<endl;
		rep(i,n){
			cin>>s>>x>>y>>z;
			tab.push_back(P(x*3+z,s));
		}
		stable_sort(tab.begin(),tab.end(),greater<P>());
		vector<P>::iterator ite=tab.begin();
		while(ite!=tab.end()){
			cout<<(*ite).second<<','<<(*ite).first<<endl;
			ite++;
		}
		tab.clear();
		now++;
	}
	return 0;
}