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
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#define REP(i,a,b) for(i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define ALL(a) (a).begin(),(a).end()
#define ifnot(a) if(not a)
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

void reader(int &a) { scanf("%d", &a); }
void reader(double &a) { scanf("%lf", &a); }
void reader(char a[]) { scanf("%s", a); }
void reader(char &a) { scanf(" %c", &a); }
void reader(ll &a) { scanf("%lld", &a); }
void reader(ull &a) { scanf("%llu", &a); }
// void reader(string& a){cin >> a;};
template<class T, class U> void reader(T& t, U& u) { reader(t); reader(u); }
template<class T, class U, class V> void reader(T& t, U& u, V& v) { reader(t); reader(u); reader(v); }

void writer(const int a, char c) { printf("%d", a); putchar(c); }
void writer(const ll a, char c) { printf("%lld", a); putchar(c); }
void writer(const ull a, char c) { printf("%llu", a); putchar(c); }
void writer(const double a, char c) { printf("%.20lf", a); putchar(c); }
void writer(const char a[]) { printf("%s", a); };
void writer(const char a[], char c) { printf("%s", a); putchar(c); };
void writer(const char a, char c) { putchar(a); putchar(c); };
template<class T> void writerLn(T t) { writer(t, '\n'); }
template<class T, class U> void writerLn(T t, U u) { writer(t, ' '); writer(u, '\n'); }
template<class T, class U, class V> void writerLn(T t, U u, V v) { writer(t, ' '); writer(u, ' '); writer(v, '\n'); }
template<class T> void writerArr(T x[], int n) { int i; if (!n) { putchar('\n'); return; }rep(i, n - 1) writer(x[i], ' '); writer(x[n - 1], '\n'); }
template<class T> void writerVec(vector<T> x) { int n = x.size(); int i; if (!n) { putchar('\n'); return; }rep(i, n - 1) writer(x[i], ' '); writer(x[n - 1], '\n'); }

vector<string> split(const string &str, char sep) { vector<string> v; stringstream ss(str); string buffer; while (getline(ss, buffer, sep)) { v.push_back(buffer); }return v; }
// #define int ll
bool test = 1;
int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
#define MAX 300000
//.....................
ull mod = (int)1e9 + 7;

struct Rank {
	int num;
	int AC_cnt;
	int t;
	bool operator < (const Rank& r) const {
		if (AC_cnt < r.AC_cnt) return true;
		if (AC_cnt == r.AC_cnt) {
			if (t > r.t) return true;
			if (t == r.t) {
				if (num < r.num) return true;
			}
		}
		return false;
	}
};

signed main(void)
{
	int i, j, k;
	while (1) {
		int M, T, P, R;
		bool AC[51][11] = {};
		int AC_cnt[51] = {};
		int elapsed_time[51] = {};
		int WA[51][11] = {};
		reader(M, T, P);
		reader(R);
		if (M == 0) return 0;
		rep(i, R) {
			int m, t, p, j;
			reader(m, t);
			reader(p, j);
			t--; p--;
			if (j == 0) {
				if (!AC[t][p]) {
					AC[t][p] = true;
					AC_cnt[t] += 1;
					elapsed_time[t] += m + WA[t][p] * 20;
				}
			}
			else {
				WA[t][p] += 1;
			}
		}
		Rank team[50];
		rep(i, T) {
			team[i].num = i;
			team[i].AC_cnt = AC_cnt[i];
			team[i].t = elapsed_time[i];
		}
		sort(&team[0], &team[T]);
		printf("%d",team[T-1].num+1);
		for (i = T - 2; i > -1; i--) {
			if (team[i].AC_cnt != team[i + 1].AC_cnt
				|| team[i].t != team[i + 1].t) {
				printf(",");
			}
			else printf("=");
			printf("%d", team[i].num+1);
		}
		puts("");
	}
	return 0;
}

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

int main()
{
	int M, T, P, R, m, t, p, j;
	while (cin >> M >> T >> P >> R, M || T || P || R) {
		vector< vector< pair<int, int> > > data(T + 1, vector< pair<int, int> >(P + 1, pair<int, int>(0,0)));
		vector< tuple<int, int, int> > score(T + 1);
		for (int i = 0; i < R; i++) {
			cin >> m >> t >> p >> j;
			if (j == 0) {
				data[t][p].first = m + data[t][p].second * 20;
				get<0>(score[t])--;
			}
			else {
				data[t][p].second++;
			}
		}
		for (int i = 1; i <= T; i++) {
			int sco = 0,pena = 0;
			for (int j = 0; j <= P; j++) {
				if (data[i][j].first) {
					sco--;
					pena += data[i][j].first;
				}
			}
			score[i] = tuple<int, int, int>(get<0>(score[i]),pena,-i);
		}
		sort(score.begin() + 1, score.end());
		tuple<int, int, int> temp = score[1];
		cout << -get<2>(score[1]);
		for (int i = 2; i <= T; i++) {
			if (get<0>(temp) == get<0>(score[i]) && get<1>(temp) == get<1>(score[i])) {
				cout << "=";
			}
			else {
				cout << ",";
			}
			cout << -get<2>(score[i]);
			temp = score[i];
		}
		cout << endl;
	}
	return 0;
}