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: isPrint = False

while True:

    inputCount = int(input())

    if inputCount == 0:
        break

    if isPrint:
        print()
    else:
        isPrint = True

    matchList = []

    for lp in range(inputCount):

        name, win, lose, draw = [item for item in input().split(" ")]
        score = int(win) * 3 + int(draw)

        matchList.append([name, score])

    matchList.sort(key=lambda item: -item[1])

    for name, score in matchList:
        print(name + "," + str(score))

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(k, v))

Python: class Team():

    def __init__(self, a, b):
        self.name = a
        self.score = b

flag = False
while True:
    N = int(input())
    if N == 0:
        break

    if flag:
        print("")
    else:
        flag = True

    teams = []
    for l in range(N):
        a,b,c,d = input().split()
        team = Team(a, int(b)*3 + int(d))
        teams.append(team)

    teams = sorted(teams, key=lambda u: u.score, reverse = True)
    for l in range(len(teams)):
        print(teams[l].name,end="")
        print(",",end="")
        print(teams[l].score)

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

Python: a = int(input())
while True:
    s = []
    for i in range(a):
        b,c,d,e = input().split()
        c = int(c)
        e = int(e)
        s.append([c*3+e,-(i),b])
    s.sort(reverse = True)
    for z in s:
        print(z[2]+","+str(z[0]))
    a = int(input())
    if a == 0:
        break
    else:
        print()

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

import sys
import os
import math

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

    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: # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0124
"""
import sys
from operator import itemgetter


def solve(data):
    result = []
    for name, win, lose, draw in data:
        score = win * 3 + draw * 1
        result.append([name, score])
    result.sort(key=itemgetter(1), reverse=True)
    return result


def main(args):
    first_data_set = True
    while True:
        n = int(input())
        if n == 0:
            break
        data = []
        for _ in range(n):
            name, win, lose, draw = input().split()
            data.append([name, int(win), int(lose), int(draw)])
        result = solve(data)
        
        if first_data_set:
            first_data_set = False
        else:
            print()
        for r in result:
            print(','.join(map(str, r)))


if __name__ == '__main__':
    main(sys.argv[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]))
    print()

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('%s,%d'%(k, v))

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]))



if __name__ == "__main__":
    main()

Python: b=False
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
    if b:print()
    b=True
    for s in sorted(d.items(), key=lambda x:x[1])[::-1]:
        print(s[0]+','+str(s[1]))

Python: f=0
while 1:
    a={}
    n=int(input())
    if n==0:break
    if f:print()
    f=1
    for i in range(n):
        b=input().split()
        a[b[0]]=[int(b[1])*3+int(b[3]),-i]
    for y,z in sorted(a.items(),key=lambda x:x[1])[::-1]:
        print('%s,%d'%(y,z[0]))

Python: from collections import defaultdict
is_init = True
while True:
  n = int(input())
  if n == 0:
    break
  
  if is_init:
    is_init = False
  else:
    print()

  result = defaultdict(list)
  scores = set()
  for _ in range(n):
    name, w, l, d = input().split()
    score = int(w) * 3 + int(d)
    result[score].append(name)
    scores.add(score)
  
  scores = sorted(list(scores), reverse=True)
  for score in scores:
    for name in result[score]:
      print(name, score, sep=",")

Python: import bisect
cnt = 0
while 1:
    outs = []
    outn = []
    n = int(input())
    if n == 0: break
    elif cnt > 0: print()
    names = []
    scores = []
    for i in range(n):
        line = list(input().split())
        name = line[0]
        names.append(name)
        w = line[1]
        l = line[2]
        d = line[3]
        score = 3*int(w) + int(d)
        tm = bisect.bisect_left(outs, score)
        outs.insert(tm, score)
        outn.insert(tm, name)
        #scores.append(score)
    #ind = 1
    for i,j in zip(reversed(outn),reversed(outs)):
        print(f'{i},{j}')
        #if ind != n: print()
        #ind += 1
    #t = zip(scores, names)
    #t = sorted(t,reverse=True)
    #names,scores = zip(*t)
    #ind = 0
    #for i,j in t:
        #print(f'{j},{i}',end='')
        #if ind != len(t)-1: print()
        #ind += 1

    cnt += 1