#include<stdio.h>
int main(){
	int n,i,i2,point[10],w,e,l,sum,maxn;
	char team[20][10];
	scanf("%d",&n);
	while(n!=0){
		for(i=0;i!=n;i++){
			scanf("%s%d%d%d",team[i],&w,&e,&l);
			sum=w*3+l;
			point[i]=sum;
		}
		for(i=0;i!=n;i++){
			maxn=0;
			for(i2=0;i2!=n;i2++){
				if(point[i2]>point[maxn]){
				maxn=i2;
				}
			}
			printf("%s,%d\n",team[maxn],point[maxn]);
			point[maxn]=0;
		}
		scanf("%d",&n);
	}
	return 0;
}