// 0124
#include <iostream>
#include <string>
#include <vector>
using namespace std;

struct team{
	string name;
	int p;
};

int main(){
	while(1){
		int n;
		cin>>n;

		if(n == 0)
			break;

		string str;
		int w, l, d;
		team t;
		vector<team> te;

		for(int i=0;i<n;i++){
			cin>>str>>w>>l>>d;
			t.name = str;
			t.p = 3*w+d;
			te.push_back(t);
		}
		
		for(int i=0;i<te.size();i++){
			for(int j=te.size()-2;j>=i;j--){
				if(te[j].p < te[j+1].p){
					t = te[j];
					te[j] = te[j+1];
					te[j+1] = t;
				}
			}
		}

		for(int i=0;i<n;i++)
			cout<<te[i].name<<","<<te[i].p<<endl;
		
		cout<<endl;
	}
	return 0;
}