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 <algorithm>

using namespace std;

int main() {
    while(true) {
        int M, T, P, R;
        cin >> M >> T >> P >> R;

        if(M == 0 && T==0 && P == 0 && R == 0) return 0;

        int m, t, p, j;
        int result[T];
        fill(result, result + T, 0);
        int time[T];
        fill(time, time + T, 0);
        int failure[T][P];
        fill(failure[0], failure[T] + P, 0);
        for (int submit = 0; submit < R; submit++) {
            cin >> m >> t >> p >> j;
            if (j == 0) {
                result[t - 1] += 1;
                time[t - 1] += m + failure[t - 1][p-1] * 20;
            } else {
                ++failure[t - 1][p-1];
            }
        }

        bool done[T];
        fill(done, done + T, false);
        int prevPoint, prevTime;
        for (int count = 0; count < T; count++) {
            int maxPoint = -1;
            int maxTeam = 0;
            int minTime = 100000;
            for (int i = T - 1; i >= 0; i--) {
                if (done[i]) continue;
                if (maxPoint < result[i]) {
                    maxPoint = result[i];
                    maxTeam = i + 1;
                    minTime = time[i];
                } else if (maxPoint == result[i]) {
                    if (minTime > time[i]) {
                        minTime = time[i];
                        maxTeam = i + 1;
                    }
                }
            }
            minTime = time[maxTeam - 1];
            if (count != 0) {
                if (maxPoint == prevPoint && minTime == prevTime) cout << "=";
                else cout << ",";
            }
            cout << maxTeam;
            done[maxTeam - 1] = true;
            prevPoint = maxPoint;
            prevTime = minTime;
        }
        cout << endl;
    }
}

C++: #include<iostream>
#include<cstring>
using namespace std;
int x[100][2], y[100][10], n, a, b, c, d, e, f, g, h, p;
int main() {
	while (true) {
		memset(x, 0, sizeof(x));
		memset(y, 0, sizeof(y));
		cin >> n >> a >> b >> c;
		if (n == 0) {
			break;
		}
		for (int i = 0; i < c; i++) {
			cin >> d >> e >> f >> g;
			if (g!=0) {
				y[e][f] += 20;
			}
			else {
				x[e][1] += d + y[e][f];
				x[e][0]++;
			}
		}
		p = 0;
		for (int i = 10; i >= 0; i--) {
			for (int j = 0; j <= 1000; j++) {
				h = 0;
				for (int k = a; k > 0; k--) {
					if (x[k][0]==i && x[k][1]==j) {
						if (h >= 1) {
							cout << '=';
						}
						else if (p >= 1) {
							cout << ',';
						}
						cout << k;
						p++;
						h++;
					}
				}
			}
		}
		cout << endl;
	}
}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()
 
#define REP(i,s,e)	for(int i=(s); i<(e); i++)
#define rep(i,n)	REP(i,0,n)
#define REPE(i,s,e)	for(int i=s; i>e; i--)
#define repe(i,n)	REPE(i,n,-1)


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<vi> vvi;
 
const int IMAX=((1<<30)-1)*2+1;
const int INF=100000000;
const double EPS=1e-10;
//int mod=1000000007
 


struct team{
	int no,ac,t,miss[10];
	team(int no): no(no){
		ac=0,t=0;
		rep(i,10) miss[i]=0;
	}
	team(const team &x): no(x.no),ac(x.ac),t(x.t){
		rep(i,10) miss[i]=x.miss[i];
	}
	bool operator <(team a){
		if(ac!=a.ac) return ac<a.ac;
		if(t!=a.t) return t>a.t;
		return no<a.no;
	}
	void write(){
		cout<<no<<" "<<ac<<" "<<t<<endl;
	}
};

bool cmp(team a,team b){
	return a<b;
}

int main(){
	int M,T,P,R;
	while(cin>>M>>T>>P>>R){
		if(M==0&&T==0&&P==0&&R==0) break;
		vector<team> t;
		rep(i,T) t.pb(i+1);
		int m,n,p,j;
		rep(i,R){
			cin>>m>>n>>p>>j;
			n--,p--;
			if(j==0){
				t[n].ac++;
				t[n].t += t[n].miss[p]*20+m;
			}
			else t[n].miss[p]++;
		} 
		//rep(i,T) t[i].write();
		sort(all(t),cmp);
		reverse(all(t));
		int a=t[0].ac,b=t[0].t;
		cout<<t[0].no;
		for(int i=1; i<T; i++){
			if(a==t[i].ac && b==t[i].t) cout<<"=";
			else cout<<",";
			a=t[i].ac,b=t[i].t;
			cout<<t[i].no;
		}
		cout<<endl;
	}
	
}