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: from inspect import currentframe


def debug_print(s):
    # print(s)
    return


def debug_key(*args):
    names = {id(v): k for k, v in currentframe().f_back.f_locals.items()}
    debug_print(', '.join(names.get(id(arg), '???')+' = '+repr(arg) for arg in args))


def solve(M, T, P, R, m, t, p, j):
    debug_print("\n-----solve-----")
    AC_COUNT = 0
    TEAM_NUMBER = 2
    SUM_TIME = 1
    QUE_NUMBER = 3


    record = [[0, 0, i + 1] + [0] * P for i in range(T)]
    debug_print(record)

    for i in range(R):
        if j[i] == 0:
            record[t[i] - 1][AC_COUNT] += 1
            record[t[i] - 1][SUM_TIME] -= m[i] + record[t[i] - 1][QUE_NUMBER + p[i] - 1] * 20
        else:
            record[t[i] - 1][QUE_NUMBER + p[i] - 1] += 1

    record.sort()
    record.reverse()
    debug_print(record)

    ans = str(record[0][TEAM_NUMBER])

    for i in range(1, T):
        if record[i][SUM_TIME] == record[i-1][SUM_TIME] and record[i][AC_COUNT] == record[i-1][AC_COUNT]:
            ans += "=" + str(record[i][TEAM_NUMBER])
        else:
            ans += "," + str(record[i][TEAM_NUMBER])

    print(ans)


    return


if __name__ == '__main__':

    while True:
        M_input, T_imput, P_imput, R_imput = map(int, input().split())
        if M_input == T_imput == P_imput == R_imput == 0:
            break
        m_input = [0 for _ in range(R_imput)]
        t_input = [0 for _ in range(R_imput)]
        p_input = [0 for _ in range(R_imput)]
        j_input = [0 for _ in range(R_imput)]

        for i in range(R_imput):
            m_input[i], t_input[i], p_input[i], j_input[i] = map(int, input().split())

        solve(M_input, T_imput, P_imput, R_imput, m_input, t_input, p_input, j_input)

Python: def main(M, T, P, R):
    team = [[0, 0, i + 1] for i in range(T)]
    teamprob = [[0] * P for i in range(T)]
    for _ in range(R):
        m, t, p, r = map(int, input().split())
        if r == 0:
            team[t - 1][0] += 1
            team[t - 1][1] -= m
            team[t - 1][1] -= teamprob[t - 1][p - 1]
        else:
            teamprob[t - 1][p - 1] += 20
    team.sort(reverse=True)
    ans = "{0}".format(team[0][2])
    for i in range(1,T):
        if team[i - 1][0] == team[i][0]:
            if team[i - 1][1] == team[i][1]:
                ans += "="
            else:
                ans += ","
        else:
            ans += ","
        ans += "{0}".format(team[i][2])
    print(ans)

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

Python: import sys

file_input = sys.stdin

for line in file_input:
    M, T, P, R = map(int, line.split())
    if M == 0:
        break
    
    # [number of solved probrems, complement of elapsed time, team number] + [rejected times] * P
    # [rejected times] * P will be accessed in reverse order.
    result = [[0, M, i] + [0] * P for i in range(T+1)]
    
    for i in range(R):
        m, t, p, j = map(int, file_input.readline().split())
        team_data = result[t]
        if j:
            team_data[-p] += 1
        else:
            team_data[0] += 1
            team_data[1] -= (m + 20 * team_data[-p])

    result.sort(reverse=True)

    for td1, td2 in zip(result[:-2], result[1:]):
        if td1[0] == td2[0] and td1[1] == td2[1]:
            print(td1[2], end='=')
        else:
            print(td1[2], end=',')
    print(result[-2][2])

Python: while True:
    M, T, P, R = map(int, input().split())
    if M == 0 and T == 0 and P == 0 and R == 0:
        break
    teams = [[0, 0, [0 for _ in range(P)], i+1] for i in range(T)]
    solved, time, miss = 0, 1, 2
    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 + teams[t][miss][p] * 20)
        else:
            teams[t][miss][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: #!/usr/bin/env python
# -*- coding: utf-8 -*-

while True:
    M,T,P,R = map(int,input().split(" "))
    if M == 0 and T == 0 and P == 0 and R == 0:
        break
    #no, correct, wrong, time
    teams = [[j,0,[0 for i in range(P+1)],0] for j in range(T+1)]

    for i in range(R):
        m,t,p,j = map(int,input().split(" "))
        if j == 0:
            if teams[t][2][p] != -1:
                teams[t][1] += 1
                teams[t][3] += teams[t][2][p] * 20 + m
                teams[t][2][p] = -1
        else:
            teams[t][2][p] += 1
    prev = None
    for t in sorted(teams[1:],key=lambda t:(t[1],-t[3],t[0]),reverse=True):
        if prev is not None:
            if prev[1] == t[1] and prev[3] == t[3]:
                print('=',end="")
            else:
                print(',',end="")
        print(t[0],end="")
        prev = t
    print()