# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
using namespace std;

int main() {
	int n;
	while (cin >> n&&n != 0) {
		vector<pair<int ,string>> result;
		string s;
		int a, b, c;
		for (int i = 0; i < n; i++) {
			cin >> s >> a >> b >> c;
			result.emplace_back(a * 3 + c * 1, s);
		}
		sort(result.begin(), result.end());
		for (int i = n-1; i >=0; i--) {
			cout << result[i].second << "," << result[i].first << endl;
		}
	}
}