Go: package main

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

func main() {
	io := NewIo()
	defer io.Flush()
	for {
		M, T, P, R := io.NextInt(), io.NextInt(), io.NextInt(), io.NextInt()
		if M == 0 {
			break
		}
		score := make([]struct{ num, time, index int }, T)
		submit := make([][]int, T)
		for i := 0; i < T; i++ {
			score[i].index = i + 1
			submit[i] = make([]int, P)
		}

		for i := 0; i < R; i++ {
			m, t, p, j := io.NextInt(), io.NextInt()-1, io.NextInt()-1, io.NextInt()
			if j == 0 {
				score[t].num++
				score[t].time += submit[t][p]*20 + m
			} else {
				submit[t][p]++
			}
		}
		sort.SliceStable(score, func(i, j int) bool {
			return score[i].num < score[j].num || score[i].num == score[j].num && score[i].time > score[j].time
		})

		for i := T - 1; i > 0; i-- {
			io.Printf("%d", score[i].index)
			if score[i].num == score[i-1].num && score[i].time == score[i-1].time {
				io.Printf("=")
			} else {
				io.Printf(",")
			}
		}
		io.Println(score[0].index)
	}
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}

Python: def main():
    while True:
        # minute,team,problem,record
        M,T,P,R = map(int, input().split(" "))
        if M == 0: break

        # [チーム1→[問題1,問題2...],チーム2→[...]...]
        data = [[0 for i in range(P)] for j in range(T)]
        # [正答数,所要合計時間]
        res = [[0, 0] for j in range(T)]
        for item in range(T):
            res[item].insert(0, item + 1)
        
        for i in range(R):
            # minute,team,problem,judge
            m,t,p,j = map(int, input().split(" "))

            # 0秒での正解を見分けるための端数1
            if j == 0: data[t - 1][p - 1] = -(data[t - 1][p - 1]) * 20 + m + 1
            else: data[t - 1][p - 1] -= 1
            
        for i in range(len(data)):
            for item in data[i]:
                if item < 0: continue
                if item != 0:
                    res[i][1] += 1
                    res[i][2] -= (item - 1)

        res = sorted(res, key = lambda x:(x[1], x[2], x[0]), reverse = True)
        
        output(res)

def output(listt):
    print(str(listt[0][0]), end = "")
    for i in range(1, len(listt)):
        if listt[i][1] == listt[i - 1][1] and listt[i][2] == listt[i - 1][2]:
            print("=" + str(listt[i][0]), end = "")
        else: print("," + str(listt[i][0]), end = "")
    print("")
main()

Python: while 1:
    M,T,P,R=map(int,input().split())
    if not M and not T and not P and not R:break
    d={i:[0,0] for i in range(1,T+1)}
    wa=[[0 for _ in range(P)] for _ in range(T)]
    for _ in range(R):
        m,t,p,j=map(int,input().split())
        if j:
            wa[t-1][p-1]+=20
        else:
            d[t][0]+=1
            d[t][1]+=(m+wa[t-1][p-1]) 
    rank=sorted(d.items(),key=lambda x:(x[1][0],-x[1][1]),reverse=True)        
    f=lambda x:"=".join(sorted(x,key=lambda y:int(y),reverse=True))
    l=[]
    b=[]
    for (i,j) in enumerate(rank):
        if i>0 and rank[i][1]!=rank[i-1][1]:
            l.append(f(b))
            b=[]
        b.append(str(j[0]))
    if b:l.append(f(b))
    print(",".join(l))

Python: import re

while True:
    Time,Team,Quiz,n = map(int,input().split())
    if Time+Team == 0:break
    score = {}
    accept = {}
    ans = ""
    for i in range(Team-1,-1,-1):
        score[i] = 0
        accept[i] = 0
    miss = [[0 for _ in range(Quiz)] for _ in range(Team)]
    for _ in range(n):
        h,t,q,j = map(int,input().split())
        if j == 0:
           accept[t-1] += 1
           score[t-1] += (h + miss[t-1][q-1])
        else:
            miss[t-1][q-1] += 20
    for i in range(max(accept.values()),-1,-1):
        stack = {}
        for t,sc in accept.items():
            if sc == i:
                stack[t] = score[t]
        stack = sorted(stack.items(), key=lambda x:x[1])
        for i,a in enumerate(stack):
            if ans != "":
                if i == 0 or a[1] != stack[i-1][1]:
                    ans += "," + str(a[0]+1)
                else:
                    ans += "=" + str(a[0]+1)
            else:
                ans += str(a[0]+1)
    print(ans)