#include <stdio.h>
#include <string.h>
int main()
{
	int n,win[10],lose[10],draw[10],point[10];
	char name[10][21],b[21];
	while(scanf("%d",&n)!=0){
		for(int i=0;i<n;i++){
			scanf("%s %d %d %d",name[i],&win[i],&lose[i],&draw[i]);
			point[i]=win[i]*3+draw[i];
		}
		for(int i=0;i<n-1;i++){
			for(int j=i+1;j<n;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<n;i++)
			printf("%s,%d\n",name[i],point[i]);
	}
}