#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
struct score{
	string str;
	int win;
	int lose;
	int draw;
	int point;
};

int main(){
	int n,a=0;
	struct score team[10];
	while(1){
		cin>>n;
		if(n==0) break;
		if(a!=0) cout<<endl;
		for(int i=0;i<n;i++){
			cin>>team[i].str>>team[i].win>>team[i].lose>>team[i].draw;
			team[i].point = team[i].win*3 + team[i].draw;
		}
		
		for(int i=0;i<n-1;i++){
			for(int j=i+1;j<n;j++){
				if(team[i].point < team[j].point){
					struct score t = team[i];
					team[i] = team[j];
					team[j] = t;
				}
			}
		}

		for(int i=0;i<n;i++){
			cout<<team[i].str<<","<<team[i].point<<endl;
		}
		a++;
	}
	return 0;
}