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 juni(tp):
    s = str(tp[0][0])
    for i in range(1, len(tp)):
        if tp[i - 1][1] == tp[i][1] and tp[i - 1][2] == tp[i][2]:
            s += "=" + str(tp[i][0])
        else:
            s += "," + str(tp[i][0])
    return s

while True:
    m, t, p, r = map(int, input().split())
    if m == 0:
        break
    tp = [[i, 0, 0, 0, [0 for j in range(p + 1)]] for i in range(t + 1)]
    for i in range(r):
        time, team, problem, hantei = map(int, input().split())
        if hantei > 0:
            tp[team][4][problem] += 1
        else:
            tp[team][1] += 1
            tp[team][2] += time
            tp[team][3] += tp[team][4][problem]
    tp.pop(0)
    for i in tp:
        i[2] += i[3] * 20
    tp.sort(reverse = True)
    tp.sort(key = lambda x:x[2])
    tp.sort(key = lambda x:x[1], reverse = True)
    print(juni(tp))

Python: # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1187&lang=jp
AC
"""
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      #  ?????????????????£?§£??¨?????£??????????????????????????????????¨?????????????????????????????????????????????§????????????
            self.penalty += 20 * self.status.pop(p, 0)
        else:
            if p in self.status:
                self.status[p] += 1
            else:
                self.status[p] = 1


def calc_result(scores):
    # ???????????????????????¢????????§?????????????????£?§£??°?????????????????????????????????????????§???????????????????????????
    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_correct = result[0][0]
        prev_time = result[0][1]
        final_output = str(result[0][2]*-1)
        for r in result[1:]:
            if r[0] == prev_correct and r[1] == prev_time:
                final_output += '='
                final_output += str(r[2]*-1)
            else:
                final_output += ','
                final_output += str(r[2]*-1)
                prev_correct = 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 == T == P == R == 0:
        quit()
    a_list = [[0, 0, i] for i in range(T)]
    wa = [[0 for j in range(P)] for i in range(T)]
    for i in range(R):
        m, t, p, j = map(int, input().split())
        t -= 1
        p -= 1
        if j == 0:
            a_list[t][0] += m + wa[t][p]*20
            a_list[t][1] += 1
        else:
            wa[t][p] += 1
    a_list.sort(key=lambda x: x[2], reverse=True)
    a_list.sort(key=lambda x: x[0])
    a_list.sort(key=lambda x: x[1], reverse=True)
    temp = [-1, -1]
    ans = ''
    for i in range(len(a_list)-1):
        ans += str(a_list[i][2]+1)
        if a_list[i][0] == a_list[i+1][0] and a_list[i][1] == a_list[i+1][1]:
            ans += '='
        else:
            ans += ','
    ans += str(a_list[-1][2]+1)
    print(ans)

Python: """
300 10 8 5
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+T+P+R == 0:
    break
  #### [TeamNumber, Solved, Time, WA]
  Tm = [[i+1,0,0,[0 for j in range(P)]]for i in range(T)]
  ####
  for i in range(R):
    m,t,p,j = map(int,input().split())
    if j==0:
      Tm[t-1][1] += 1
      Tm[t-1][2] += m+Tm[t-1][3][p-1]*20
      Tm[t-1][3][p-1] = 0
    else:
      Tm[t-1][3][p-1] += 1
  Tm.sort(key=lambda x:(x[1],-x[2],x[0]), reverse=True)
  ans = []
  for i in range(T):
    ans.append(str(Tm[i][0]))
    if i<T-1:
      if Tm[i][1]==Tm[i+1][1] and Tm[i][2]==Tm[i+1][2]:
        ans.append("=")
      else:
        ans.append(",")
  print("".join(ans))