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 <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, cnt = 0;
    while(cin >> n, n){
        if(cnt) puts("");
        cnt++;
        vector<pair<int, string>> v(n);
        for (int i = 0; i < n; ++i) {
            string s; int a, b, c;
            cin >> s >> a >> b >> c;
            v[i] = {a*300+c*100+n-i, s};
        }
        sort(v.begin(),v.end(), greater<>());
        for (int i = 0; i < n; ++i) {
            cout << v[i].second << "," << v[i].first/100 << "\n";
        }
    }
    return 0;
}

C++: #include <cstdio>
#include <algorithm>
using namespace std;

typedef struct tm_{
	char name[32];
	int s;
	bool operator<(const struct tm_ &r) {
		return s > r.s;
	}
}TM;
TM t[11];

int main(){
	bool st = true;
	int w,l,d;
	int n;
	while(scanf("%d",&n),n != 0){
		if(!st){
			printf("\n");
		}
		st = false;

		for(int i = 0; i < n; i++){
			scanf("%s%d%d%d",t[i].name,&w,&l,&d);
			t[i].s = w*3+d*1;
		}
		sort(t,t+n);
		for(int i = 0; i < n; i++){
			printf("%s,%d\n",t[i].name,t[i].s);
		}
	}
	return 0;
}

C++: #include <iostream>
#include <map>
#include <set>
using namespace std;

typedef pair<int, string> P;
set<P> team;

int main(void){
  int n;
  while(cin >> n, n){
    for(int i = 0; i < n; i++){
      string tname;
      int w, l, d;
      cin >> tname >> w >> l >> d;
      pair<int, string> t;
      t.first = w * 3 + d;  t.second = tname;
      team.insert(t);
    }
    set<P>::reverse_iterator it;
    for(it = team.rbegin(); it != team.rend(); it++){
      cout << (*it).second << "," << (*it).first << endl;
    }
    cout << endl;
    team.clear();
  }
  return 0;
}

C++: #include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	int n;
	bool first=true;
	while(cin>>n,n){
		if(!first) cout<<endl;
		first=false;
		vector<pair<pii, string>> v(n);
		rep(i,n){
			string s;
			cin>>s;
			int a,b,c;
			cin>>a>>b>>c;
			v[i] = mkp(pii(-a*3-c,i),s);
		}
		sort(ALL(v));
		rep(i,n){
			cout<<v[i].S<<","<<-v[i].F.F<<endl;
		}
	}
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <cfloat>
#include <map>
using namespace std;

struct data{
	
	string name;
	int w;
	int l;
	int e;
	int t;
	static bool s  (const data& x,const data& y){
        return x.t>y.t;
    }
};

int main(){
	
	int n;
	while(cin>>n,n!=0){
		vector<data> m(n);
		for(int i=0;i<n;i++){
			cin>>m[i].name>>m[i].w>>m[i].l>>m[i].e;
			m[i].t=m[i].w*3+m[i].e;
		}
		sort(m.begin(),m.end(),data::s);
		for(int i=0;i<n;i++)
			cout<<m[i].name<<","<<m[i].t<<endl;
	}
}

C++: #define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <bitset>
#include <complex>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl;
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef complex<double> CD;

int main() {
	bool first = true;
	while (true) {
		int n; cin >> n;
		if (n == 0)break;

		if (!first)puts("");
		first = false;

		vector<pair<int, pair<int, string>>> ans;
		rep(i, n) {
			string s; int a, b, c;
			cin >> s >> a >> b >> c;
			ans.pb(mp(a * 3 + c, mp(n - i, s)));
		}
		SORT(ans); REVE(ans);

		rep(i, n) {
			cout << ans[i].second.second << "," << ans[i].first << endl;
		}
	}
}