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 pb push_back
#define mt make_tuple
#define all(a) (a).begin(),(a).end()
#define frep(i,a,n) for(int i=(a);i<(n);++i)
#define rep(i, n) for(int i=0;i<(n);++i)
#define rrep(i, n) for(int i=n-1;i>=0;--i)
#define debug(x) cout << #x << " : " << x << " ------------ " << endl;
using namespace std;
struct Record {
    int id, ac, ct;
    int acm[11], wa[11];
    
    bool operator<(const Record& rhs) const {
        if (ac != rhs.ac)
            return ac > rhs.ac;
        if (ct != rhs.ct)
            return ct < rhs.ct;
        return id > rhs.id;
    }
};
int main()
{
    int M, T, P, R;
    while (cin >> M >> T >> P >> R, M | T | P | R) {
        Record team[T + 1];
        rep(i, T + 1) team[i] = {i};
        while (R--) {
            int m, t, p, j;
            cin >> m >> t >> p >> j;
            if (j > 0)
                ++team[t].wa[p];
            else {
                team[t].ct += m + 20 * team[t].wa[p];
                ++team[t].ac;
            }
        }
        sort(team, team + T + 1);
        rep(i, T + 1) {
            if (team[i].id == 0) continue;
            cout << team[i].id;
            if (i < T - 1) {
                if (team[i].ac == team[i+1].ac && team[i].ct == team[i+1].ct)
                    cout << "=";
                else cout << ",";
            }
        }
        cout << endl;
    }
    return EXIT_SUCCESS;
}

C++: #include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <sstream>
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>

using namespace std;

#define ll long long
#define pi pair<int,int>
#define pll pair<ll,ll>
#define pii pair<int,pi>
#define X first
#define Y second
#define pb push_back
#define ab(x) ((x)<0?(-(x)):(x))
#define xx(x) ((x)*(x))
#define mp make_pair
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
#define vpi vector<pi>
#define vpll vector<pll>
#define ALL(x) (x).begin(),(x).end()
#define Max (1<<30)
#define LLMax (1ll<<60)
template<class T>string ToString(T t){stringstream s;s<<t;return s.str();}
template<class T>void ToOther(T&t,string a){stringstream s(a);s>>t;}


int M,T,P,R;
int a[105][12];
bool ac[105][12];
int pe[105];

struct data{
	int sol,pe,idx;
	data(int A,int B,int C){
		sol=A;
		pe=B;
		idx=C;
	}
};
bool sf(data a,data b){
	if(a.sol==b.sol){
		if(a.pe==b.pe)return a.idx>b.idx;
		return a.pe<b.pe;
	}return a.sol>b.sol;
}
vector<data> v;

int main(){

	while(cin>>M>>T>>P>>R,M){
		memset(a,0,sizeof(a));
		memset(ac,0,sizeof(ac));
		memset(pe,0,sizeof(pe));

		for(int i=0;i<R;i++){
			int m,t,p,r;
			scanf("%d%d%d%d",&m,&t,&p,&r);

			if(ac[t][p])continue;

			if(r==0){
				ac[t][p]=1;
				pe[t]+=m;
				pe[t]+= 20*a[t][p];
			}else a[t][p]++;
		}

		v.clear();
		for(int i=1;i<=T;i++){
			int cnt=0;
			for(int k=1;k<=P;k++)if(ac[i][k])cnt++;
			v.pb( data(cnt,pe[i],i) );
		}
		sort(ALL(v),sf);

		printf("%d",v[0].idx);
		for(int i=1;i<v.size();i++){
			if(v[i-1].sol== v[i].sol && v[i-1].pe==v[i].pe)printf("=");
			else printf(",");
			printf("%d",v[i].idx);
		}
		puts("");
	}

}

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

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define RFOR(i, a, b) for (int i = (int)(b - 1); i >= (int)(a); --i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define RREP(i, n) for (int i = (int)(n - 1); i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define SQ(x) ((x) * (x))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
    int M, T, P, R;
    while (cin >> M >> T >> P >> R, M|T|P|R) {
        vector<pair<pii, int>> score(T);
        REP(i, T) {
            score[i] = {{0, 0}, i+1};
        }

        vvi penalty(T, vi(P));
        REP(i, R) {
            int m, t, p, j;
            cin >> m >> t >> p >> j;
            t--;
            p--;
            if (j == 0) {
                score[t].first.first++;
                score[t].first.second -= m + 20 * penalty[t][p];
            } else {
                penalty[t][p]++;
            }
        }

        RSORT(score);
        printf("%d", score[0].second);
        FOR(i, 1, SZ(score)) {
            if (score[i-1].first.first == score[i].first.first &&
                score[i-1].first.second == score[i].first.second) {
                printf("=");
            } else {
                printf(",");
            }
            printf("%d", score[i].second);
        }
        printf("\n");
    }
}