#include<stdio.h>
#include<string.h>

int main(){
	
	char coun[11][21];
	int score[11],win,lose,draw;
	int i,j,n;
	
	for(;;){
		scanf("%d",&n);
		if(n==0)break;
		for(i=0;i<n;i++){
			scanf("%s",coun[i]);
			scanf("%d%d%d", &win, &lose, &draw);
			score[i]=win*3+draw;
		}
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(score[i]>score[j]){
					score[10]=score[j];
					score[j]=score[i];
					score[i]=score[10];
					strcpy(coun[10],coun[j]);
					strcpy(coun[j],coun[i]);
					strcpy(coun[i],coun[10]);
				}
			}
		}
		for(i=0;i<n;i++){
			printf("%s,%d\n",coun[i],score[i]);
		}
	}
	return 0;
}