#include<stdio.h>
#include<string.h>
int main(void)
{
	int n,a,b,c,w[10],s[10]={0,1,2,3,4,5,6,7,8,9},i,j,temp;
	char as[10][21];
	while(1){
	scanf("%d",&n); //???????????°
		if(n==0)break;
	for(i=0;i<n;i++){
		scanf("%s%d%d%d",as[i],&a,&b,&c);
		w[i]=a*3+c;
	}
	for(i=1;i<n;i++){
		for(j=0;j<n;j++){
			if(w[i]>w[j]){
				temp=w[i];
				w[i]=w[j];
				w[j]=temp;
				temp=s[i];
				s[i]=s[j];
				s[j]=temp;
			}
		}
	}
	for(i=0;i<n;i++){
		printf("%s,%d\n",as[s[i]],w[i]);
	}
	}
	return 0;
}