/*************************************/
/*     ??\?????\?????\?????\??¬???????????±???006???????????????2?????? */
/*          coded by Y.Suganuma      */
/*************************************/
#include <stdio.h>

int main()
{
	int i1, i2, k, n, p[10], p1, p2, p3;
	char name[10][21];
					// ??\???????????\?????????????£???????
	scanf("%d", &n);
					// ??\???????????\?????????????£?????????????????????????????????????????????????
	for (i1 = 0; i1 < n; i1++) {
		scanf("%s %d %d %d", name[i1], &p1, &p2, &p3);
		p[i1] = 3 * p1 + p3;
	}
					// ????????????
	for (i1 = 0; i1 < n; i1++) {
		k = -1;
		for (i2 = 0; i2 < n; i2++) {
			if (p[i2] >= 0) {
				if (k < 0 || p[i2] > p[k])
					k = i2;
			}
		}
		printf("%s,%d\n", name[k], p[k]);
		p[k] = -1;
	}

	return 0;
}