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>

using namespace std;

int main(void){
    int m,t,p,r;
    int mk,tk,pk,jk;
    int a[2][50][10];
    vector<pair<int,int> > vp;
    int i,j,k,x,y,z;
    while(true){
        cin >> m >> t >> p >> r;
        if(m == 0) break;
        memset(a,0,sizeof(a));
        for(i = 0;i < r;i++){
            cin >> mk >> tk >> pk >> jk;
            tk--;pk--;
            if(jk){
                a[0][tk][pk] += 20;
            }
            else{
                a[1][tk][pk] = mk + a[0][tk][pk];
            }
        }
        vp.clear();
        for(i = 0;i < t;i++){
            x = 0;
            y = 0;
            for(j = 0;j < p;j++){
                if(a[1][i][j]){
                    x++;
                    y+=a[1][i][j];
                }
            }
            vp.push_back(make_pair(x*100000000-y,i));
        }
        sort(vp.begin(),vp.end());
        i = vp.size();
        x = vp[--i].first;
        cout << vp[i].second+1;
        for(;i > 0;){
            if(x == vp[--i].first){
                cout << "=";
            }
            else cout << ",";
            x = vp[i].first;
            cout << vp[i].second+1;
        }
        cout << endl;
    }
}

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

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;



int main(void) {
	
	while (1) {
		int M, T, P, R;
		int tmp1, tmp2;
		int dp[51][11] = {};


		cin >> M >> T >> P >> R;
		if (M == 0) {
			break;
		}
		vector<int>m(R), t(R), p(R), j(R), time(T+1, 0), count(T+1, 0);
		vector< pair<int, int> > res(T);
		FOR(i, 0, R - 1) {
			cin >> m[i] >> t[i] >> p[i] >> j[i];
			if (j[i] == 0) {
				count[t[i]]++;
				time[t[i]] += dp[t[i]][p[i]] * 20 + m[i];
			}
			else {
				dp[t[i]][p[i]]++;
			}
		}
		FOR(i, 0, T - 1) {
			res[i].first = count[i + 1];
			res[i].second = i + 1;
		}
		sort(res.begin(), res.end());

		FOR(i, 0, T) {
			FOR(s, i + 1, T - 1) {
				if (res[i].first == res[s].first) {
					if (time[res[i].second] < time[res[s].second]) {
						tmp1 = res[i].second;
						res[i].second = res[s].second;
						res[s].second = tmp1;
					}
				}
			}
		}

		bool flag = true;
		bool check = true;
		if (T == 1) {
			cout << 1 << endl;
		}
		else {
			RFOR(i, T - 1, 1) {
				if (res[i].first != res[i - 1].first) {
					if (check == false) {
						cout << "=" << res[i].second;
						check = true;
						continue;
					}
					check = true;
					if (flag == true) {
						cout << res[i].second;
						flag = false;
					}
					else {
						cout << "," << res[i].second;
					}
				}
				else if (time[res[i].second] != time[res[i - 1].second]) {
					if (check == false) {
						cout << "=" << res[i].second;
						check = true;
						continue;
					}
					check = true;
					if (flag == true) {
						cout << res[i].second;
						flag = false;
					}
					else {
						cout << "," << res[i].second;
					}
				}
				else {
					if (flag == true) {
						flag = false;
						if (check == true) {
							cout << res[i].second;
							check = false;
						}
						else {
							cout << "=" << res[i].second;
						}
						
					}
					else {
						if (check == true) {
							cout << "," << res[i].second;
							check = false;
						}
						else {
							cout << "=" << res[i].second;
						}
					}
				}
			}

			if (res[1].first != res[0].first) {
				cout << "," << res[0].second;
			}
			else if (time[res[1].second] != time[res[0].second]) {
				cout << "," << res[0].second;
			}
			else {
				cout << "=" << res[0].second;
			}

			cout << endl;
		}
		
	}
}