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 <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <queue>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <cassert>
#include <iomanip>

using namespace std;

#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;
typedef complex<int> P;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tii;
const double EPS = 1e-10;
const double PI = acos(-1.0);


const int pena = 20;

struct st{
	int id;
	int ac;	//
	int t;	//
	vector<int> ac_t;
	vector<int> wa_cnt;

	st(int p){
		ac = 0; t = 0;	//
		ac_t = vector<int>(p, -1);
		wa_cnt.resize(p);
	}
	bool operator<(const st& o) const{
		return (*this).ac == o.ac ? (*this).t > o.t : (*this).ac < o.ac;
	}
	bool operator==(const st& o) const{
		return (*this).ac == o.ac && (*this).t == o.t;
	}
	bool operator!=(const st& o) const{
		return !((*this) == o);
	}

	void calc(){
		for(int i=0;i<ac_t.size();++i){
			if(ac_t[i] == -1) continue;
			++ac;
			t += ac_t[i] + wa_cnt[i] * pena;
		}
	}
};

void debug(vector<st> team){
	for(auto& o : team){
		cerr<< o.id<< " : ";
		cerr<< o.ac<< " "<< o.t;
		cerr<< " , ";
		for(auto& p : o.ac_t) cerr<< " "<< p;
		cerr<< " , ";
		for(auto& p : o.wa_cnt) cerr<< " "<< p;
		cerr<< endl;
	}
}

bool solve(){
	int m, t, p, r;
	cin>> m>> t>> p>> r;
	if(!m && !t && !p && !r) return false;
	vector<st> team(t, st(p));
	for(int i=0;i<t;++i) team[i].id = i + 1;

	for(int i=0;i<r;++i){
		int m, t, p, j;
		cin>> m>> t>> p>> j;
		--t; --p;
		if(j == 0){
			team[t].ac_t[p] = m;
		}else{
			++team[t].wa_cnt[p];
		}
	}

	//debug(team);
	for(auto& o : team) o.calc();
	sort(rall(team));
	//debug(team);

	for(int i=0;i<team.size();++i){
		if(i) cout<< ",";
		vector<int> tmp;
		tmp.push_back(team[i].id);
		for(int j=i+1;j<team.size();++j){
			if(team[i] != team[j]) break;
			tmp.push_back(team[j].id);
		}
		sort(rall(tmp));
		for(int j=0;j<tmp.size();++j){
			if(j) cout<< "=";
			cout<< tmp[j];
		}
		i += tmp.size() - 1;
	}
	cout<< endl;

	return true;
}

int main(){
	cout.setf(ios::fixed); cout.precision(10);
	while(solve());
	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define fi first
#define se second

using namespace std;

typedef pair<int,int>P;
typedef pair<P,int>pi;

int pena[55][15];

int main()
{
    while(1){
        int m,t,p,r;
        cin >> m >> t >> p >> r;
        if(m == 0){
            break;
        }
        vector<pi> vec(t);
        rep(i,t){
            rep(j,p+1){
                pena[i][j] = 0;
            }
            vec[i] = pi(P(0,0),-i);
        }
        rep(i,r){
            int a,b,c,d;
            cin >> a >> b >> c >> d;
            b--;
            if(d){
                pena[b][c]++;
            }else{
                (vec[b].fi).fi--;
                (vec[b].fi).se += a + pena[b][c]*20;
            }
        }
        sort(vec.begin(),vec.end());
        P prv = P(-1,-1);
        rep(i,(int)vec.size()){
            if(prv == vec[i].fi){
                if(i){
                    cout << "=" << -vec[i].se+1;
                }else{
                    cout << -vec[i].se+1;
                }
            }else{
                prv = vec[i].fi;
                if(i){
                    cout << "," << -vec[i].se+1;
                }else{
                    cout << -vec[i].se+1;
                }
            }
        }
        cout << "\n";
    }
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

signed main(void)
{
  while(true) {
    int m, t, p, r;
    cin >> m >> t >> p >> r;
    if(!m && !t && !p && !r) break;
    VVI rec;
    REP(i, r) {
      int a, b, c, d;
      cin >> a >> b >> c >> d;
      rec.PB({a, b, c, d});
    }
    sort(ALL(rec));
    int wa[55][15] = {0};
    VVI ac;
    REP(i, t) ac.PB({0, 0, (int)i+1});
    REP(i, r) {
      //??£?§£
      if(!rec[i][3]) {
        ac[rec[i][1]-1][0]++;
        ac[rec[i][1]-1][1] += wa[rec[i][1]-1][rec[i][2]] * 20 + rec[i][0];
      } else {
        wa[rec[i][1]-1][rec[i][2]]++;
      }
    }
    REP(i, t) {
      ac[i][0] *= -1;
      ac[i][2] *= -1;
    }
    sort(ALL(ac));
    cout << -1*ac[0][2];
    FOR(i, 1, t) {
      if(ac[i][0] == ac[i-1][0] && ac[i][1] == ac[i-1][1]) {
        cout << "=";
      } else {
        cout << ",";
      }
      cout << -1*ac[i][2];
    }
    cout << endl;
  }

  return 0;
}