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++: #include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;


struct SCORE {
	ll ac, pena, id;
	SCORE(ll _ac, ll _pena, ll _id) :ac(_ac), pena(_pena), id(_id) {}
	SCORE() :ac(0), pena(0), id(0) {}
	bool operator<(const SCORE& s) {
		if (ac == s.ac) {
			if (pena == s.pena) return id > s.id;
			else return pena < s.pena;
		}
		else {
			return ac > s.ac;
		}
	}
	bool operator ==(const SCORE& s) {
		return pena == s.pena && ac == s.ac;
	}
};
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	int kkt = 89;
	while (kkt) {
		ll M, T, P, R; scanf("%lld %lld %lld %lld", &M, &T, &P, &R); if (M == 0 && T == 0 && P == 0 && R == 0) break;
		vector<SCORE> score(T); for (int i = 0; i < T; i++) score[i].id = i + 1;
		vector<vector<ll>> miss(T, vector<ll>(P));
		for (int i = 0; i < R; i++) {
			ll m, t, p, j; scanf("%lld %lld %lld %lld", &m, &t, &p, &j); t--; p--;
			if (j == 0) {
				score[t].ac++;
				score[t].pena += m + miss[t][p];
			}
			else {
				miss[t][p] += 20;
			}
		}
		sort(score.begin(), score.end());
		for (int i = 0; i < T; i++) {
			cout << score[i].id;
			if (i == T - 1) cout << "\n";
			else {
				if (score[i] == score[i + 1]) cout << "=";
				else cout << ",";
			}
		}
	}
	return 0;

}

C++: #include <bits/stdc++.h>

using namespace std;

struct team {
    int id, acc, time, was[10];
    team(int i=0) : id(i), acc(0), time(0) {fill(was, was+10, 0);}

    void judge(int m, int p, int j)
    {
        if(j)
        {
            was[p-1]++;
        }
        else
        {
            acc++;
            time += m + 20 * was[p-1];
        }
    }
};

bool operator<(const team& a, const team& b)
{
    if(a.acc==b.acc)
    {
        if(a.time==b.time)
        {
            return a.id>b.id;
        }
        return a.time<b.time;
    }
    return a.acc>b.acc;
}

int main()
{
    int m, t, p, r;
    while(cin >> m >>t >> p >> r, m|t|p|r)
    {
        team ts[t];
        for(int i=0; i<t; i++) ts[i] = team(i+1);
        while(r--)
        {
            int mi, ti, pi, ji;
            cin >> mi >> ti >> pi >> ji;
            ts[ti-1].judge(mi, pi, ji);
        }
        sort(ts, ts+t);
        cout << ts[0].id;
        for(int i=1; i<t; i++)
        {
            cout << ((ts[i].acc==ts[i-1].acc && ts[i].time==ts[i-1].time) ? "=" : ",") << ts[i].id;
        }
        cout << endl;
    }
}