#include<cstdio>
#include<cstring>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,i,j,k;
	int kati,make,hiki,ten[10],ss[10];
	char team[10][21];
	while(1) {
		scanf("%d",&n);
		if(n==0) break;
		for(i=0;i<n;i++) {
			scanf("%s %d %d %d",team[i],&kati,&make,&hiki);
			ten[i]=(kati*3)+(hiki*1);
			ss[i]=(kati*3)+(hiki*1);
		}
		sort(ten,ten+n,greater<int>());
		for(i=0;i<n;i++) {
			for(j=0;j<n;j++) {
				if(ten[i]==ss[j]) {
					printf("%s,%d",team[j],ten[i]);
					break;
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}