#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct nx { 
string name;
int cost;
};
int main() {
	int n, f=0;
	while (cin>>n) {
		if (n&&f) cout<<endl;
		else if (f) break;
		vector<nx> m(n);
		for (int i=0; i<n; i++) {
			cin>>m[i].name;
			int a,b,c; cin>>a>>b>>c;
			m[i].cost=a*3+c*1;
		}
		for (int i=0; i<n; i++) {
			for (int j=i+1; j<n; j++) {
				if (m[i].cost<m[j].cost) swap(m[i],m[j]);
			}
		}
		for (int i=0; i<n; i++) {
			cout<<m[i].name<<","<<m[i].cost<<endl;
		}
		f++;
	}
}