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 <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int M, T, P, R;
    while (cin >> M >> T >> P >> R, M) {
        vector<int> m(R), t(R), p(R), j(R);
        vector<vector<int>> wa(T, vector<int>(P, 0)), ac(T, vector<int>(P, -1));
        REP (i, R) {
            cin >> m[i] >> t[i] >> p[i] >> j[i];
            t[i]--; p[i]--;
            if (j[i] == 0) ac[t[i]][p[i]] = m[i];
            else wa[t[i]][p[i]]++;
        }
        vector<tuple<int, int, int>> v(T);
        REP (i, T) {
            int num = 0, sum = 0;
            REP (k, P) if (ac[i][k] != -1) {
                num++;
                sum += ac[i][k] + wa[i][k] * 20;
            }
            v[i] = make_tuple(-num, sum, -i);
        }
        sort(v.begin(), v.end());
        REP (i, v.size()) {
            int num, sum, idx;
            tie(num, sum, idx) = v[i];
            if (i) {
                int pnum, psum, pidx;
                tie(pnum, psum, pidx) = v[i - 1];
                if (num == pnum && psum == sum) cout << "=";
                else cout << ",";
            }
            cout << idx * -1 + 1;
        }
        cout << endl;
    }
}

C++: #include <iostream>
#include <vector>
using namespace std;

int main(int argc, char *argv[])
{
    int m, t, p, r, mk, tk, pk, jk, score, team;
    bool flg;
    while (cin >> m >> t >> p >> r, m) {
        vector<int> ans(t + 1, 0);
        vector<int> penalty(t + 1, 0);
        vector<vector<int> > wrong(t + 1, vector<int>(p + 1, 0));
        for (int i = 0; i < r; ++i) {
            cin >> mk >> tk >> pk >> jk;
            if (jk != 0) {
                wrong[tk][pk]++;
            } else {
                ans[tk]++;
                penalty[tk] += 20 * wrong[tk][pk] + mk;
            }
        }
        for (int i = 0; i < t; ++i) {
            score = -1;
            if (i != 0 && !flg)
                cout << ',';
            else if (i != 0)
                cout << '=';
            for (int j = 1; j <= t; ++j) {
                if (score < ans[j]) {
                    score = ans[j];
                    team = j;
                    flg = false;
                } else if (score == ans[j]) {
                    if (penalty[team] == penalty[j])
                        flg = true;
                    else
                        flg = false;
                    team = (penalty[team] < penalty[j]) ? team : j;
                }
            }
            cout << team;
            ans[team] = -2;
        }
        cout << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; ++i)
using namespace std;


int main(void){
	int M,T,P,R;
	while(cin >> M >> T >> P >> R,M){
		vector<int> solved[11][3010];
		vector<int> ts(T,0);
		vector<int> tt(T,0);
		vector<vector<int>> pen(T,vector<int>(10,0));
		
		rep(i,R){
			int m,t,p,j;
			cin >> m >> t >> p >> j;
			t--,p--;
			if(ts[t]&(1<<p)) continue;

			if(j==0){
				ts[t]|=(1<<p);
				tt[t]+=m + 20*pen[t][p];
			}else{
				pen[t][p]++;
			}
		}

		for(int i = T-1; i >=0;--i){
			const int s = __builtin_popcount(ts[i]);
			const int t = tt[i];
			solved[s][t].push_back(i+1);
		}


		string ans="";
		bool first = true;
		for(int i=P;i>=0;--i){
			for(int j=0;j<=3000;++j){
				if(solved[i][j].empty()) continue;
				const int n = solved[i][j].size();
				
				if(first) 
					first = false;
				else
					ans +=",";
				rep(k,n) ans += (k?"=":"") + to_string(solved[i][j][k]);
			}
		}

		cout << ans << endl;
	}
	return 0;
}