#include <stdio.h>
#include <string.h>
int main(void)
{
	int team,win,lose,draw,point[10];
	char name[10][21],b[21];
	while(1){
		scanf("%d",&team);
		if(team==0)
			break;
		for(int i=0;i<team;i++){
			scanf("%s %d %d %d",name[i],&win,&lose,&draw);
			point[i]=win*3+draw;
		}
		for(int i=0;i<team-1;i++){
			for(int j=i+1;j<team;j++){
				if(point[i]<point[j]){
					int a=point[i];
					point[i]=point[j];
					point[j]=a;
					strcpy(b,name[i]);
					strcpy(name[i],name[j]);
					strcpy(name[j],b);
				}
			}
		}
		for(int i=0;i<team;i++)
			printf("%s,%d\n",name[i],point[i]);
		printf("\n");
	}
	return 0;
}