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 <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;
 
#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 EPS 1e-8
#define F first
#define S second
#define mkp make_pair
 
static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
typedef pair<pii,string> ttt;
static const int INF=1<<24;
 
template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
    v.assign(a,vector<T>(b,t));
}
 
//v.erase(unique(v.begin(),v.end()),v.end());


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

C++: #include<stdio.h>

int main()
{
	int score[11],win,lose,draw,point[11];
	int n,i,j;
	char str[11][21];
	
	for(;;){
		scanf("%d",&n);
		if(n==0)break;
		for(i=0;i<n;i++){
			scanf("%s",str[i]);
			scanf("%d%d%d", &win, &lose, &draw);
			score[i]=win*3+draw;
			point[i]=score[i];
		}
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(point[i]>point[j]){
					point[10]=point[i];
					point[i]=point[j];
					point[j]=point[10];
				}
			}
		}
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(point[i]==score[j]){
					printf("%s,%d\n",str[j],score[j]);
					score[j]=-1;
					break;
				}
			}
		}
		printf("\n");
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	multimap<int,string,greater<int> > data;
	while(1){
		data.clear();
		int n;
		cin >> n;
		if(n==0) break;
		string tmp;
		int a,b,c;
		REP(i,n){
			cin >> tmp >> a >> b >> c;
			data.insert(multimap<int,string>::value_type(a*3+c,tmp));
		}
		for(multimap<int,string>::iterator it = data.begin();it != data.end(); it++){
			cout<<(*it).second<<","<<(*it).first<<endl;
		}
		cout << endl;
	}
	return 0;
}

C++: #include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n;
    int hoge=0;
    while(cin>>n,n){
        if(hoge++)cout<<endl;
        vector<pii>v;
        vector<string>amausa;
        rep(i,n){
            int gotiusa=0;
            string rabit; cin>>rabit;
            amausa.push_back(rabit);
            int kokoa,rize,tino; cin>>kokoa>>rize>>tino;
            gotiusa+=kokoa*3+tino;
            v.push_back(pii(gotiusa,-i));
        }
        sort(all(v),greater<pii>());
        rep(i,n)cout<<amausa[-1*v[i].second]<<","<<v[i].first<<endl;
    }
}

C++: #include <iostream>
#include <string>
#include <map>
#define V multimap<int,string>::value_type
using namespace std;
int main()
{
  int n,w,l,d;
  string s;
  bool p = false;
  for(;;){
    cin >> n;
    if(n == 0) break;
    if(p) cout << endl;
    multimap<int,string, greater<int> > m;
    while(n--){
      cin >> s >> w >> l >> d;
      m.insert( V(w*3+d*1,s) );
    }
    multimap<int,string>::iterator it = m.begin();
    while(it != m.end()){
      cout << (*it).second << "," << (*it).first << endl;
      it++;
    }
    p = true;
  }
  return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
#include<cstdlib>
#include<iostream>
using namespace std;
int main(void)
{
	int i,j,k,x,n;
	int win,lose,drow;
	char kuni[10][21];
	int tokuten[10];
	while(1) {
		cin>>n;if(n==0)break;
		for(i=0;i<n;i++) {
			cin>>kuni[i]>>win>>lose>>drow;
			tokuten[i]=win*3+drow;
		}
		for(i=0;i<n;i++) {
			for(j=i+1;j<n;j++) {
				if(tokuten[i]<tokuten[j]) {
					swap(tokuten[i],tokuten[j]);
					swap(kuni[i],kuni[j]);
				}
			}
		}
		for(i=0;i<n;i++) cout<<kuni[i]<<","<<tokuten[i]<<endl;
		cout<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;

struct team{
	string name;
	int score;
	int num;
	team(string n, int s, int nu):name(n), score(s), num(nu){}
	bool operator<(const team &r)const{
		if(score == r.score) return num > r.num;
		return score < r.score;
	}
};

int main(){
	int n;
	while(cin >> n, n){
		vector<team> v;
		rep(i, n){
			string name;
			int w, l, d;
			cin >> name >> w >> l >> d;
			v.push_back(team(name, w*3+d, i));
		}
		sort(rev(v));
		rep(i, n){
			cout << v[i].name << ',' << v[i].score << endl; 
		}
	}

	return 0;
}