#include<stdio.h>
#include<string.h>
int main(void)
{
	int i,j,N,a,b,c,OZA[10],t;
	char S[10][10],T[10];
	scanf("%d",&N);
	for(i=0;i<N;i++){
		scanf("%s %d %d %d",S[i],&a,&b,&c);
		OZA[i] = 3 * a + c;
	}
	for(i=0;i<N;i++){
		for(j=i+1;j<N;j++){
			if(OZA[i] < OZA[j]){
				strcpy(T,S[i]);
				strcpy(S[i],S[j]);
				strcpy(S[j],T);
				t = OZA[i];
				OZA[i] = OZA[j];
				OZA[j] = t;
			}
		}
	}
	for(i=0;i<N;i++){
		printf("%s,%d\n",S[i],OZA[i]);
	}
	return 0;
}