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)
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include <stdio.h>
#include <functional>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

string x(string s, const string cs, const string se) {
	int pos = 0;
	while ((pos = s.find_first_of(se)) != string::npos) {
		s.replace(pos, 1, cs);
	}
	return s;
}

string y(string a) {
	int pos4 = 0, pos9 = 0;
	a = x(a, "3", "5");
	a = x(a, "5", "6");
	a = x(a, "6", "7");
	a = x(a, "7", "8");
	int pos = a.length();
	if ((pos4 = a.find_first_of("4")) != string::npos && (pos9 = a.find_first_of("9")) != string::npos)
	{
		if (pos4 > pos9) {//4>9
			a = a.replace(pos9, 1, "7");
			pos = pos9 + 1;
		}
		else {
			a = a.replace(pos4, 1, "3");
			pos = pos4 + 1;
		}
	}
	else if ((pos4 = a.find_first_of("4")) != string::npos) {
		a = a.replace(pos4, 1, "3");
		pos = pos4 + 1;
	}
	else if ((pos9 = a.find_first_of("9")) != string::npos) {
		a = a.replace(pos9, 1, "7");
		pos = pos9 + 1;
	}
	while (pos != a.length()) {
		a = a.replace(pos, 1, "7");
		pos++;
	}
	return a;
}

int n;
int m;
int aji[100000];

int saiki(){
	return 0;
}

int main(){
	int m, t, p, r;
	while (cin >> m >> t >> p >> r && !(m == 0 && t == 0 && p == 0 && r == 0)){
		vector<pair<int, pair<int, int>>> juni; // テヲツュツ」ティツァツ」テヲツ閉ー テヲツ卍づゥツ鳴?テ」ツδ?」ツδシテ」ツδ?・ツ青?テァツュツ氾」ツ?暗」ツ?ョテ」ツ?淌」ツつ?」ツ?ョvector)
		int teamscore[50]; // テ・ツ青?」ツδ?」ツδシテ」ツδ?」ツ?ョテ」ツつケテ」ツつウテ」ツつ「
		int teamsecond[50]; // テ・ツ青?」ツδ?」ツδシテ」ツδ?」ツ?ョテヲツ卍づゥツ鳴?
		int teamincorr[50][2000]; // テ・ツ青?」ツδ?」ツδシテ」ツδ?・ツ青?・ツ閉湘ゥツ。ツ古」ツ?ョテゥツ鳴禿ゥツ?陛」ツ?暗」ツ?淌・ツ崢榲ヲツ閉ー
		int teamincorrcnt[50]; // テ・ツ青?」ツδ?」ツδシテ」ツδ?」ツ?ョテヲツュツ」ティツァツ」テ」ツ?療」ツ?淌・ツ閉湘ゥツ。ツ古」ツ?ョテゥツ鳴禿ゥツ?陛」ツ?暗」ツ?淌・ツ崢榲ヲツ閉ー
		for (int i = 0; i < 50; i++) {
			teamscore[i] = 0;
			teamsecond[i] = 0;
			teamincorrcnt[i] = 0;
			for (int j = 0; j < 2000; j++) {
				teamincorr[i][j] = 0;
			}
		}
		for (int i = 0; i < r; i++) {
			int mk, tk, pk, jk;
			cin >> mk >> tk >> pk >> jk;
			if (jk == 0) { // テヲツュツ」ティツァツ」
				teamscore[tk - 1]++; // テヲツュツ」ティツァツ」テヲツ閉ーテ」ツつ津・ツ「ツ療」ツつ?」ツ??
				teamincorrcnt[tk - 1] += teamincorr[tk - 1][pk];
				teamsecond[tk - 1] += mk + 20 * teamincorr[tk - 1][pk];
			}
			else { // テゥツ鳴禿ゥツ?陛」ツ??
				teamincorr[tk - 1][pk]++;
			}
		}
		for (int i = 0; i < t; i++) {
			juni.push_back(make_pair(teamscore[i], make_pair(1000000 - teamsecond[i], i + 1)));
		}
		sort(juni.begin(), juni.end());

		int score = -1;
		int jikan = -1;
		for (int i = t - 1; i >= 0; i--) {
			if (i != t - 1) {
				if (score == juni[i].first && jikan == juni[i].second.first) {
					cout << "=";
				}
				else {
					cout << ",";
				}
			}
			cout << juni[i].second.second;
			score = juni[i].first;
			jikan = juni[i].second.first;
		}
		cout << endl;
	}
	return 0;
}