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()
	}
}

Python: flag = True
while True:
    n = int(input())
    if n == 0: break
    answer = {}
    for _ in range(n):
        result = input().split()
        country = result[0]
        win, lose, draw = map(int, result[1:])
        score = win * 3 + draw
        answer[country] = score
    if flag:
        flag = False
    else:
        print()
    for c, s in sorted(answer.items(), key=lambda x: -x[1]):
        print(c + ',' + str(s))

Python: b=False
while True:
    n = int(input())
    if n==0:break
    d=dict()
    if b:print()
    b=True
    for _ in range(n):
        line = input().split()
        tmp = int(line[1])*3+int(line[3]*1)
        if tmp in d:
            d[tmp].append(line[0])
        else:
            d[tmp] = []
            d[tmp].append(line[0])
    for k, vs in sorted(d.items(), key=lambda x: x[0])[::-1]:
        for v in vs:
            print('{0},{1}'.format(v, k))

Python: c = 0
while True:
    c +=1
    L = []
    num = int(input())
    if num == 0:
        break
    
    for i in range(num):
        name, w, l, d = input().split()
        w = int(w)
        d = int(d)
        L.append((i,name,w*3+d))
    
    L.sort(key=lambda x: (-x[2],x[0]))
    
    if c > 1:
        print()
        
    for l in L:
        print("{},{}".format(l[1], l[2]))

Python: b=False
while True:
    n = int(input())
    if n==0:break
    d=dict()
    if b:print()
    for _ in range(n):
        t = input().split()
        d[t[0]]=int(t[1])*3+int(t[3])*1
    b=True
    for s in sorted(d.items(), key=lambda x:x[1])[::-1]:
        print(s[0]+','+str(s[1]))

Python: b=False
while True:
    n = int(input())
    if n==0:break
    d=dict()
    if b:print()
    for _ in range(n):
        t = input().split()
        d[t[0]]=int(t[1])*3+int(t[3])*1
    b=True
    for s in sorted(d.items(), key=lambda x:x[1])[::-1]:
        print('{0},{1}'.format(s[0],s[1]))

Python: st=True
while True:
    n=int(input())
    if n==0:
        break
    if st==False:
        print()

    team={}
    for _ in range(n):
        data=input().split(" ")
        team[data[0]]=3*int(data[1])+int(data[3])
    team=team.items()
    team=sorted(team,key=lambda w:w[1],reverse=True)
    for t in team:
        print("{0},{1}".format(*t))
    st=False

Python: # Aizu Problem 00124: League Match Score Sheet
#
import sys, math, os, copy

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


first = True
while True:
    N = int(input())
    if N == 0:
        break
    if first:
        first = False
    else:
        print()
    scoresheet = []
    for n in range(N):
        s = input().split()
        team = s[0]
        won = int(s[1])
        draw = int(s[3])
        scoresheet.append([team, n, 3 * won + draw])
    scoresheet = sorted(scoresheet, key=lambda x: (-x[2], x[1]))
    for team, n, points in scoresheet:
        print("%s,%d" % (team, points))

Python: # AOJ 0124 League Match Score Sheet
# Python3 2018.6.21 bal4u

f = True
while True:
	n = int(input())
	if n == 0: break
	tbl = []
	for i in range(n):
		name, w, l, d = list(input().split())
		tbl.append([name, i, 3*int(w)+int(d)])
	if f: f = False
	else: print()
	for i in sorted(tbl, key=lambda x:(-x[2],x[1])): print(i[0], ',', i[2], sep='')

Python: while True:
    n = int(input())
    if n == 0:
        break
    dataset = []
    for _ in range(n):
        name, w, l, d = input().split()
        dataset.append((name, 3*int(w) + int(d), n-len(dataset)))
    for name, score, _ in sorted(dataset, key=lambda x: (x[1], x[2]))[::-1]:
        print(name + "," + str(score))

Python: while True:
    n = int(input())
    if n==0:break
    d=dict()
    for _ in range(n):
        t = input().split()
        d[t[0]]=int(t[1])*3+int(t[3])*1
    print()
    for s in sorted(d.items(), key=lambda x:x[1])[::-1]:
        print(s[0]+','+str(s[1]))

Python: # -*- coding: utf-8 -*-

import sys
import os
import math

for i, s in enumerate(sys.stdin):
    n = int(s)
    if n == 0:
        break
    elif i != 0:
        print()

    A = []

    for i in range(n):
        lst = input().split()
        name = lst[0]
        w = int(lst[1])
        l = int(lst[2])
        d = int(lst[3])
        score = 3 * w + d
        A.append((score, -i, name))
    A.sort(reverse=True)

    for a in A:
        score = a[0]
        name = a[2]
        print('{},{}'.format(name, score))

Python: def getScore(d):
    return int(d[1]) * 3 + int(d[3])
    
isFirst = True

while 1:
    n = int(input())
    if n == 0:
        break
    if not isFirst:
        print()
    table = []
    for i in range(0,n):
        d = list(_ for _ in input().split())
        score = getScore(d)
        table.append((d[0],score))
    table.sort(key=lambda i:i[1],reverse=True)
    
    for n,s in table:
        print(str(n) + ',' + str(s))
    isFirst = False

Python: # -*- coding: utf-8 -*-

import sys
import os
import math

for s in sys.stdin:
    n = int(s)
    if n == 0:
        break

    A = []

    for i in range(n):
        lst = input().split()
        name = lst[0]
        w = int(lst[1])
        l = int(lst[2])
        d = int(lst[3])
        score = 3 * w + d
        A.append((score, -i, name))
    A.sort(reverse=True)

    for a in A:
        score = a[0]
        name = a[2]
        print('{},{}'.format(name, score))
    print()

Python: f = True
while True:
    n = int(input())
    if n == 0: break
    tbl = []
    for i in range(n):
        name, w, l, d = list(input().split())
        tbl.append([name, i, 3*int(w)+int(d)])
    if f: f = False
    else: print()
    for i in sorted(tbl, key=lambda x:(-x[2],x[1])): print(i[0], ',', i[2], sep='')

Python: def main():
    while True:
        n = int(input())
        if n == 0: break

        teams = []
        for i in range(n):
            row = input().split()
            teams.append([row[0], 0])
            s_t = 0
            for e, p in zip(row[1:], [3, 0, 1]):
                s_t += int(e) * p
            teams[i][1] = s_t
        
        for t in sorted(teams, key=lambda x: x[1], reverse=True):
            print("{},{}".format(t[0], t[1]))
        print()



if __name__ == "__main__":
    main()