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,m,t,p,j;

    while(cin>>M>>T>>P>>R, M|T|P|R){
        int cnt[51]={};
        int time[51]={};
        int penalty[51][11]={};
        int s[51]={};

        /*????????¨??????????????£????¨????*/
        while(R--){
            cin>>m>>t>>p>>j;
            if(j==0){
                ++cnt[t];
                time[t] += m+penalty[t][p];
            }
            else penalty[t][p]+=20;
        }

        /*???????????¨??????*/
        for(t=1;t<=T;t++)s[t]=t;

        /*??????????????????*/
        for(int a=1;a<T;a++){
            for(int b=T;b>a;b--){
                if(cnt[s[b]]<cnt[s[b-1]]
                   ||(cnt[s[b]]==cnt[s[b-1]] && time[s[b]]>time[s[b-1]])
                   ||(cnt[s[b]]==cnt[s[b-1]] && time[s[b]]==time[s[b-1]] && s[b]<s[b-1]))
                    swap(&s[b],&s[b-1]);
            }
        }

        /*??????????????????????????????*/
        for(t=T;t>=1;t--){
            cout<<s[t];
            if(t==1)break;
            if(cnt[s[t]]==cnt[s[t-1]] && time[s[t]]==time[s[t-1]])cout<<"=";
            else cout<<",";
        }
        cout<<endl;

    }
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<map>
#include<queue>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)
#define RREP(i, a, n) for(int i=n-1; i>=a; i--)
#define INF 1000000000
#define MP(a, b) make_pair(a, b)
#define F first
#define S second

int main() {
	int M, T, P, R;
	while (cin >> M >> T >> P >> R) {
		vector<pair<int, pair<int, int>>> vp;
		int pena[51][11];

		REP(i, 0, T) vp.push_back(MP(0, MP(0, i + 1)));
		REP(i, 0, 51) REP(j, 0, 11) pena[i][j] = 0;

		REP(i, 0, R) {
			int m, t, p, j;
			cin >> m >> t >> p >> j;
			t--;
			p--;

			if (j == 0) {
				vp[t].F++;
				vp[t].S.F -= (pena[t][p] + m);
			}
			else {
				pena[t][p] += 20;
			}
		}

		sort(vp.begin(), vp.end());
		reverse(vp.begin(), vp.end());

		cout << vp[0].S.S;
		REP(i, 1, vp.size()) {
			if (vp[i - 1].F > vp[i].F) {
				cout << "," << vp[i].S.S;
			}
			else if (vp[i - 1].S.F > vp[i].S.F) {
				cout << "," << vp[i].S.S;
			}
			else {
				cout << "=" << vp[i].S.S;
			}
		}

		cout << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define REP(a,b,c) for(int a=b; a<(int)c; a++)
#define REPE(a,b,c) for(int a=b; a<=(int)c; a++)
#define REPD(a,b,c) for(int a=b; a>(int)c; a--)
#define rep(a,b) REP(a,0,b)
#define repd(a,b) REPD(a,b,0)
class _datas{
public:
  int m;
  int t;
  int p;
  int j;
};
class _score{
public:
  int p;
  int t;
  _score(int p, int t){
    this->p = p;
    this->t = t;
  }
};
typedef long long int ll;
using namespace std;

  

int main(){
  while(true){
    int M,T,P,R;
    cin >> M >> T >> P >> R;
    if(M == 0) break;
    vector<_datas> datas(R);
    rep(i,R) cin >> datas[i].m >> datas[i].t >> datas[i].p >> datas[i].j;
    //rep(i,R) cout << datas[i].m << " "<< datas[i].t << " "<< datas[i].p << " "<< datas[i].j << " " << endl;
    vector<_score> scores(T+1,_score(0,0));
    REPE(i,1,T){
      vector<int> miss_cnt(P,0);
      rep(j,R){
        _datas data = datas[j];
        if(data.t == i){
          if(data.j == 0){
            scores[i].p++;
            scores[i].t += data.m + miss_cnt[data.p]*20;
          }else{
            miss_cnt[data.p]++;
          }
        }
      }
    }
    /*cout << "score" << endl;
    REPE(i,1,T){
      cout<<i<<":" << scores[i].p << " " << scores[i].t << endl;
    }*/
    _score b_score = _score(0,0);
    REPE(i,1,T){
      int max_idx = 1;
      REPE(j,2,T){
        if(scores[j].p > scores[max_idx].p || (scores[j].p==scores[max_idx].p && scores[j].t <= scores[max_idx].t)){
          max_idx = j;
        }
      }
      if(i != 1){
        if(b_score.p == scores[max_idx].p && b_score.t==scores[max_idx].t) cout << "=";
        else cout << ",";
      }
      cout << max_idx;
      b_score = scores[max_idx];
      scores[max_idx] = _score(-1,0);
    }
    cout << endl;
  }
  return 0;
}