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: # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1187&lang=jp

"""
import sys
from sys import stdin
input = stdin.readline


class Team(object):
    def __init__(self, id):
        self.id = id
        self.correct = 0        #  ??£?§£??°
        self.time = 0           #  ????????????
        self.penalty = 0        #  ??????????????£
        self.status = {}        #  ?????£?§£?????¶??? key: ????????????, value: ????????£????????°

    def judge(self, m, p, j):
        if j == 0:
            self.correct += 1
            self.time += m
            if p in self.status:
                self.penalty += 20 * self.status[p]
                del self.status[p]
        else:
            if p in self.status:
                self.status[p] += 1
            else:
                self.status[p] = 1


def calc_result(scores):
    # ???????????????????????¢????????§?????????????????£?§£??°?????????????????????????????????????????§???????????????????????????l
    result = []                 #  ??????????????¨??????[??£?§£??°*(-1), ????????????, ???????????????*(-1)] ??????????????§?¨??????????
    for i, s in enumerate(scores[1:], start=1):
        if s is not None:
            result.append([-s.correct, s.time+s.penalty, s.id*-1]) #  sort()??????????????????????????£????????????????????????????????£?§£??°??¨??????????????????-1???????????????
        else:
            result.append([0, 0, -i])
    result.sort()
    return result


def main(args):
    # M, T, P, R = 300, 10, 8, 5,
    # data = [[50, 5, 2, 1,], [70, 5, 2, 0], [75, 1, 1, 0], [100, 3, 1, 0], [150, 3, 2, 0]]

    while True:
        M, T, P, R = map(int, input().split())
        if M == 0 and T == 0 and P == 0 and R == 0:
            break
        data = [[int(i) for i in input().split()]  for x in range(R)]

        scores = [None] * (T+1)
        for d in data:
            m, t, p, j = d
            if scores[t] == None:
                team = Team(t)
                scores[t] = team
            scores[t].judge(m, p, j)

        # ???????????????
        result = calc_result(scores)

        # ?????????????????????????????????
        prev_corrent = result[0][0]
        prev_time = result[0][1]
        final_output = str(result[0][2]*-1)
        for r in result[1:]:
            if r[0] == prev_corrent and r[1] == prev_time:
                final_output += '='
                final_output += str(r[2]*-1)
            else:
                final_output += ','
                final_output += str(r[2]*-1)
                prev_corrent = r[0]
                prev_time = r[1]
        print(final_output)


if __name__ == '__main__':
    main(sys.argv[1:])

Python: while True:
    M, T, P, R = map(int, input().split())
    if M == 0: break
    teams = [[0, 0, i+1] for i in range(T)]
    miss = [[0 for _ in range(P)] for _ in range(T)]
    solved, time = 0, 1
    logs = [map(int, input().split()) for _ in range(R)]
    for m, t, p, r in logs:
        t -= 1
        p -= 1
        if r == 0:
            teams[t][solved] += 1
            teams[t][time] -= (m + miss[t][p] * 20)
        else:
            miss[t][p] += 1
    teams = sorted(teams, reverse=True)
    before_s, before_t = 0, 0
    for i in range(T):
        s, t, n = teams[i]
        if i != 0:
            print('=' if (s == before_s and t == before_t) else ',', end='')
        before_s, before_t = s, t
        print(n, end='')
    print('')

Python: class Team:
    def __init__(self, num, P):
        self.num = num
        self.times = [ 0 for _ in range(P) ]
        self.solved = [ False for _ in range(P) ]
        self.ps = None
        self.tt = None
    
    def submit(self, m, p, j):
        if j == 0:
            self.solved[p] = True
            self.times[p] += m
        else:
            self.times[p] += 20
    
    def probsSolved(self):
        if self.ps == None:
            self.ps = len(list(filter(lambda x: x, self.solved)))
        return self.ps

    def totalTime(self):
        if self.tt == None:
            total = 0
            for i in range(len(self.solved)):
                if self.solved[i]:
                    total += self.times[i]
            self.tt = total
        return self.tt

if __name__ == '__main__':
    while True:
        M, T, P, R = [ int(x) for x in list(filter(lambda x: x != '', \
            input().strip().split(' '))) ]

        if M == 0 and T == 0 and P == 0 and R == 0:
            break

        teams = [ Team(n + 1, P) for n in range(T) ]

        for _ in range(R):
            m, t, p, j = [ int(x) for x in list(filter(lambda x: x != '', \
                input().strip().split(' '))) ]
            teams[t-1].submit(m, p - 1, j)

        teams.sort(key=lambda t: (-t.probsSolved(), t.totalTime(), -t.num))

        print(teams[0].num, end='')
        for i in range(1, T):
            team = teams[i]
            prevTeam = teams[i - 1]
            if team.probsSolved() == prevTeam.probsSolved() and \
                team.totalTime() == prevTeam.totalTime():
                print("={}".format(team.num), end='')
            else:
                print(",{}".format(team.num), end='')
        print()