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: while True:
    M,T,P,R = map(int,input().split())
    if T == 0: break
    wrong = [[0 for i in range(P)] for j in range(T)]
    right = [0 for i in range(T)]
    pena = [0 for i in range(T)]
    for i in range(R):
        m,t,p,j = map(int,input().split())
        t,p = t-1,p-1
        if j == 0:
            right[t] += 1
            pena[t] += wrong[t][p] * 20 + m
        else:
            wrong[t][p] += 1
    result = []
    for t in range(T):
        result.append((-right[t], pena[t], -(t+1)))
    result.sort()
    ans = str(-result[0][2])
    for (r1,p1,t1),(r2,p2,t2) in zip(result, result[1:]):
        if r1 == r2 and p1 == p2:
            ans += '='
        else:
            ans += ','
        ans += str(-t2)
    print(ans)

Python: while True:
    m, t, p, r = map(int, input().split())
    if m == t == p == r == 0:
        break

    score = [[-1 for i in range(p + 1)] for j in range(t + 1)]
    for i in range(r):
        mi, ti, pi, j = map(int, input().split())
        if not j:
            score[ti][pi] = mi - (score[ti][pi] + 1) * 20
        else:
            score[ti][pi] -= 1

    data = list()
    for ti in range(1, t + 1):
        ans = 0
        pen = 0
        for pi in range(1, p + 1):
            if score[ti][pi] >= 0:
                ans += 1
                pen += score[ti][pi]
        data.append((ans, -pen, ti))

    data.sort(reverse = True)
    for i in range(t - 1):
        ans, pen, ti = data[i]
        pen = -pen
        print(ti, end = "")
        if ans > data[i + 1][0] or pen < - data[i + 1][1]:
            print(",", end = "")
        else:
            print("=", end = "")
    print(data[t - 1][2])

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