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 "iostream"
#include "cstring"
#include "vector"
using namespace std;
typedef struct res
{
	int solve;
	int time;
	int id;

	static bool comp(const res& l, const res& r)
	{
		if(l.solve!=r.solve) return l.solve>r.solve;
		if(l.time!=r.time) return l.time<r.time;
		return l.id>r.id;
	}
}res;


int main(void)
{
	int M,T,P,R;
	while (cin>>M>>T>>P>>R,M) {
		int penalty[M][P];
		memset(penalty,0,sizeof(penalty));
		res result[T];
		for (int i = 0; i < T; i++) {
			result[i].solve=0;
			result[i].time=0;
			result[i].id=i+1;
		}
		for (int i = 0; i < R; i++) {
			int m,t,p,r;
			cin>>m>>t>>p>>r;
			if(!r)
			{
				result[t-1].solve+=1;
				result[t-1].time+=m+20*penalty[t-1][p-1];
			}
			else penalty[t-1][p-1]++;
		}
		sort(result,result+T,res::comp);
		for (int i = 0; i < T; i++) {
			if(i!=0)
			{
				if(result[i-1].solve==result[i].solve&&result[i-1].time==result[i].time)
				{
					cout<<"=";
				}
				else cout<<",";
			}
			cout<<result[i].id;
		}

		cout<<endl;
	}
	return 0;
}

C++: #include<stdio.h>
#include<string.h>
typedef struct {
	int id;
	int ac ;
	int time;
	int pt[300];
	int ok[20];

} Player;

int M, T, P,R;



void makeScore(int n, Player * A)
{
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= P; j++)
		{
			if (A[i].ok[j] == 0)
			{
				if (A[i].pt[j])
					A[i].time += (20 * A[i].pt[j]);
			}

		}
		
	}
}

void makeRank(int n, Player*A)
{
	int i, j;
	Player temp;
	for (int i = 0; i < n; i++)
		for (int j = n; j > i + 1; j--)
		{
			if (A[j].ac>A[j - 1].ac)
			{
				temp = A[j]; A[j] = A[j - 1]; A[j - 1] = temp;
			}
			else if (A[j].ac == A[j - 1].ac)
			{
				if (A[j].time < A[j - 1].time)
				{
					temp = A[j]; A[j] = A[j - 1]; A[j - 1] = temp;
				}
				else if (A[j].time == A[j - 1].time)
				{
					if (A[j].id > A[j - 1].id)
					{
						temp = A[j]; A[j] = A[j - 1]; A[j - 1] = temp;
					}
				}
			}
		}
}

void Print(int n, Player *A)
{
	int i;
	for (i = 1; i <= n; i++)
	{
		
		printf("%d", A[i].id);
		if (A[i].ac == A[i + 1].ac&&A[i].time==A[i+1].time)
			printf("=");
		else if (i != n)
			printf(",");
	}
	printf("\n");
}
int main()
{

	int i;
	int time, team, num, ok;
	Player plr[100];
	
	while (scanf("%d%d%d%d", &M, &T, &P, &R) && M || T || R || P)
	{
		for (int i = T; i>=1;i--)
		{
			memset(plr[i].pt, 0, sizeof(plr[i].pt));
			memset(plr[i].ok, -1, sizeof(plr[i].ok));
			plr[i].ac = plr[i].time = 0;
			plr[i].id = i;
		}
	
		for (i = 0; i < R; i++)
		{
			scanf("%d%d%d%d", &time, &team, &num, &ok);
			if (ok == 0)
			{
				plr[team].ac++;
				plr[team].time = time;
				plr[team].ok[num] = 0;
			}
			else
			{
				
				plr[team].pt[num]++;
			}
		}

		makeScore(T, plr);
		makeRank(T, plr);
		Print(T, plr);



	}
}

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

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) x.begin(), x.end()
struct Data {
    int count, penalty, id;
    Data(int id_) : count(0), penalty(0), id(id_) {}
};

bool comp(const Data &d1, const Data &d2) {
    if (d1.count != d2.count)
        return d1.count > d2.count;
    else if (d1.penalty != d2.penalty)
        return d1.penalty < d2.penalty;
    else
        return d1.id > d2.id;
}

int pena[101][1010];
bool solved[101][1010];
void solve() {
    int M, T, P, R;
    cin >> M >> T >> P >> R;
    if (M == 0) exit(0);
    REP(i, T + 1) REP(j, P + 1) {
        solved[i][j] = false;
        pena[i][j] = 0;
    }
    vector<Data> v;
    REP(i, T) {
        Data d(i);
        v.push_back(d);
    }
    REP(_, R) {
        int m, t, p, j;
        cin >> m >> t >> p >> j;
        p--, t--;
        if (j != 0) {
            pena[t][p]++;
        } else {
            if (!solved[t][p]) {
                solved[t][p] = true;
                v[t].count++;
                v[t].penalty += 20 * pena[t][p];
                v[t].penalty += m;
            }
        }
    }
    sort(v.begin(), v.end(), comp);
    Data d(T);
    v.push_back(d);
    REP(i, T) {
        cout << v[i].id + 1;
        if (i != T - 1) {
            if (v[i].count == v[i + 1].count && v[i].penalty == v[i + 1].penalty)
                cout << '=';
            else
                cout << ',';
        }
    }

    cout << endl;
    // REP(i, T) { cout << v[i].id + 1 << " " << v[i].count << " " << v[i].penalty << endl; }
}

signed main() {
    while (true) solve();
}