Go: package main

import (
	"bufio"
	"fmt"
	"os"
		"strconv"
	"strings"
	"sort"
	)

var scanner = bufio.NewScanner(os.Stdin)

type Country struct {
	Name  string
	Score int
}

func (c Country) String() string {
	return fmt.Sprintf("%s,%d", c.Name, c.Score)
}

type ByScore []Country

func (a ByScore) Len() int           { return len(a) }
func (a ByScore) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ByScore) Less(i, j int) bool { return a[i].Score > a[j].Score }

func main() {
	// countries := []Country{
	// 	{"japan", 3},
	// 	{"america", 4},
	// 	{"canada", 2},
	// }
	// sort.Sort(ByScore(countries))
	// fmt.Println(countries)
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		countries := make([]Country, n)
		for i := range countries {
			scanner.Scan()
			input := strings.Split(scanner.Text(), " ")
			tmp := new(Country)
			tmp.Name = input[0]
			var x int
			for j := 1; j < 4; j++ {
				switch j {
				case 1:
					x, _ = strconv.Atoi(input[j])
				case 2:
					x = 0
				case 3:
					x, _ = strconv.Atoi(input[j])
					x *= 3
				}
				tmp.Score += x
			}
			countries[i] = *tmp
		}
		sort.Sort(ByScore(countries))
		for _, v := range countries {
			fmt.Println(v)
		}
		fmt.Println()
	}
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

bool func(pair< string, int > a, pair< string, int > b){
	return a.second > b.second;
}

int main(){
	
	int n, w, l, d, c = 0;
	string country;
	vector< pair< string, int > > v;
	
	while(cin >> n, n){
		v.clear();
		
		for(int i = 0; i < n; ++i){
			cin >> country >> w >> l >> d;
			v.push_back(pair< string, int >(country, w * 3 + d));
		}
		
		sort(v.begin(), v.end(), func);
		
		
		if(c != 0) cout << endl;
		++c;
		
		for(vector< pair< string, int > >::iterator it = v.begin(); it != v.end(); ++it){
			cout << (it->first) << "," << (it->second) << endl;
		}
		
	}
	
	return 0;
}

C++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
class Team {
public:
	string name;
	int score;
	bool operator <(const Team &other) {
		return this->score > other.score;
	}
	bool operator >(const Team &other) {
		return other.score < this->score;
	}
	Team(string s, int x) {
		this->name = s;
		this->score = x;
	}
};
signed main() {
	int n, cnt(0);
	while (cin >> n, n) {
		vector<Team>team;
		rep(i, 0, n) {
			string s; int w, l, d;
			cin >> s >> w >> l >> d;
			Team a(s, w * 3 + d);
			team.push_back(a);
		}
		sort(team.begin(), team.end());
		if (cnt++)cout << endl;
		each(it, team)cout << it->name << "," << it->score << endl;
	}
	return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <string>

using namespace std;

int main() {
	int n;
	string team[10];
	int tokuten[10][4];
	string kari;
	int karikari;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		for (int i = 0; i < n; i++) {
			cin >> team[i] >> tokuten[i][0] >> tokuten[i][1] >> tokuten[i][2];
			tokuten[i][3] = 3 * tokuten[i][0] + tokuten[i][2];
		}

		for (int i = n-1; i > 0; i--) {
			for (int j = 0; j < i; j++) {
				if (tokuten[j][3] < tokuten[j+1][3]) {
					kari = team[j];
					team[j] = team[j+1];
					team[j+1] = kari;
					karikari = tokuten[j][3];
					tokuten[j][3] = tokuten[j+1][3];
					tokuten[j+1][3] = karikari;
				}
			}
		}

		for (int i = 0; i < n; i++) {
			cout << team[i] << "," << tokuten[i][3] << endl;
		}
		cout << endl;

	}
	return 0;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>

using namespace std;

typedef long long ll;
typedef pair<string,int> P;

class mycmp{
public:
	bool operator()(const P p1, const P p2){
		return p1.second > p2.second;
	}
};

int main(){
	char buf[64];
	int win,lose,draw;	
	int n;
	bool isnl = false;
	while(~scanf("%d",&n)){
		if(n==0) break;
		if(isnl){
			cout << endl;
		}
		vector<P> data;
		for(int i=0,j=0;i<n;i++){
			scanf("%s %d %d %d",buf,&win,&lose,&draw);
			data.push_back(P(buf,win*3+draw*1));
		}
		
		sort(data.begin(),data.end(),mycmp());

		for(int i=0;i<data.size();i++){
			printf("%s,%d\n",data[i].first.c_str(),data[i].second);
		}
		isnl=true;
	}
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,n) for(int i=0; i<n; i++)
#define INF (1<<20)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;

struct Data{
	string name;
	int w, l, d,sum;
};

int main()
{
	int n;
	
	while (cin >> n, n) {

		vector<Data> s(n);
		for (int i = 0; i < n; i++) {
			cin >> s[i].name >> s[i].w >> s[i].l >> s[i].d;
			s[i].sum = s[i].w * 3 + s[i].d;
		}

		for (int i = 0; i < n - 1; i++)
			for (int j = i + 1; j < n; j++)
				if (s[i].sum < s[j].sum)swap(s[i], s[j]);

		for (int i = 0; i < n; i++)
			cout << s[i].name << "," << s[i].sum << endl;
	}
	return 0;
}

C++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

template<typename V>
constexpr string join(const V &v, const string &sep) {
  stringstream ss;
  if (v.size()) ss << v[0];
  loop(i, 1, v.size()) ss << sep << v[i];
  return ss.str();
}

void solve() {
  int n;
  vs out;
  while (cin >> n, n) {
    vector<pair<int, string>> v;
    while (n--) {
      string name;
      int w, l, d;
      cin >> name >> w >> l >> d;
      v.emplace_back(w * 3 + d, name);
    }
    stable_sort(all(v), [](auto a, auto b) { return a.fi > b.fi; });
    ostringstream ss;
    for (auto &x : v) ss << x.se << ',' << x.fi << endl;
    out.pb(ss.str());
  }
  cout << join(out, "\n");
}