#include<iostream>
#include<vector>
#include<string>
#include<map>
using namespace std;

int main() {
	while (1) {
		int a;
		cin >> a;
		if (a == 0)break;
		map<double, string>s;
		auto c = 0.01;
		for (int b = 0; b < a; b++) {
			string d; double e, f, g;
			cin >> d >> e >> f >> g;
			s.insert(pair<double, string>((e * 3 + f * 0 + g * 1 + (1 - c)), d));
			c+=0.01;
		}
		for (auto i = s.end();; i--) {
			if (i == s.end())i--;
			cout << i->second << "," <<(int)(i->first) << endl;
			if (i == s.begin())break;
		}
		cout << endl;
	}
}