#include <iostream>
#include <string>
using namespace std;
int main(){
	int n,i,win,draw,lose,point[10],tn;
	string str[10],tstr;
	while(cin >> n && n){
		for(i=0;i<n;i++){
			cin >> str[i] >> win >> lose >> draw;
			point[i] = (win*3)+(draw*1);
		}
		for(i=0;i<n-1;i++){
			for(int j=i+1;j<n;j++){
				if(point[i] < point[j]){
					tstr = str[i];
					str[i] = str[j];
					str[j] = tstr;
					tn = point[i];
					point[i] = point[j];
					point[j] = tn;
				}
			}
		}
		for(i=0;i<n;i++){
			cout << str[i] << "," << point[i] << endl;
			if(i == n-1){
			cout << "\n";
			}
		}
	}
	return 0;
}