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 <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define between(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30

typedef pair<int, pair<int, int> > pii;

int M, T, P, R;

bool cmp(const pii &a, const pii &b){
  if(a.S.F != b.S.F) return a.S.F > b.S.F;
  if(a.S.S != b.S.S) return a.S.S < b.S.S;
  return a.F > b.F;
}

int main(){
  while(scanf("%d%d%d%d",&M, &T, &P, &R) && M+T+P+R){
    vector<vector<int> >pe(T, vector<int>(P));
    rep(i, T) rep(j, P) pe[i][j] = 0;
    vector<pii>team(T); // team, ac, penalty
    rep(i, T) team[i] = make_pair(i, make_pair(0, 0));

    int m, t, p, j;
    rep(i, R){
      scanf("%d%d%d%d", &m, &t, &p, &j); t--; p--;
      if(j){
	pe[t][p]++;
      }else{
	team[t].S.F++;
	team[t].S.S += m + (20 * pe[t][p]);
      }
    }
    //    rep(i, T) printf("%d %d %d\n", team[i].F+1, team[i].S.F, team[i].S.S);
    sort(team.begin(), team.end(), cmp);

    //    rep(i, T) printf("%d ", team[i].F+1); puts("");
    rep(i, T) printf(i?team[i-1].S.F==team[i].S.F&&team[i-1].S.S==team[i].S.S?"=%d":",%d":"%d", team[i].F+1); puts("");
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

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

int main() {
	int m, t, p, r;

	while (cin >> m >> t >> p >> r) {
		if (m == 0 && t == 0 && p == 0 && r == 0) {
			break;
		}

		vector<Q> krank(t);

		for (int i = 0; i < t; i++) {
			krank[i] = Q(0, P(0, i + 1));
		}

		vector< vector<int> > wa(t, vector<int>(p, 0));

		int mm, tt, pp, jj;

		for (int i = 0; i < r; i++) {
			cin >> mm >> tt >> pp >> jj;
			if (jj == 0) {
				krank[tt - 1].first++;
				(krank[tt - 1].second).first -= mm;
				(krank[tt - 1].second).first -= 20 * wa[tt - 1][pp - 1];
			}
			else {
				wa[tt - 1][pp - 1]++;
			}
		}

		sort(krank.begin(), krank.end(), greater<Q>());

		cout << (krank[0].second).second;
		for (int i = 1; i < t; i++) {
			if (krank[i].first == krank[i - 1].first) {
				if ((krank[i].second).first == (krank[i - 1].second).first) {
					cout << '=' << (krank[i].second).second;
				}
				else {
					cout << ',' << (krank[i].second).second;
				}
			}
			else {
				cout << ',' << (krank[i].second).second;
			}
		}
		cout << endl;

	}

	return 0;
}

C++: #include <bits/stdc++.h>
  
using namespace std;
typedef long long ll;
  
#define rep(i, n) for(int i=0; i<(n); ++i)
 
class team {
public:
    int id, solve, time, miss[11];
    bool operator<(const team & rhs) const{
        if(solve > rhs.solve) return true;
        else if(solve==rhs.solve && time < rhs.time) return true;
        else if(solve==rhs.solve && time == rhs.time && id > rhs.id) return true;
        return false;
    }
};
int main(void){
    int M, T, P, R;
    int m, t, p, j;
    team teams[51];
    while(cin >> M >> T >> P >> R && M) {
        rep(i, T) {
            teams[i].id = i+1;
            teams[i].solve = 0;
            teams[i].time = 0;
            rep(j, P+1) teams[i].miss[j] = 0;
        }
        rep(i, R) {
            cin >> m >> t >> p >> j;
            t--;
            if(j == 0) {
                teams[t].solve++;
                teams[t].time += m + teams[t].miss[p] * 20;
            } else {
                teams[t].miss[p]++;
            }
        }
        sort(teams, teams+T);
        rep(i, T-1) {
            cout << teams[i].id;
            if(teams[i].solve==teams[i+1].solve && teams[i].time==teams[i+1].time) {
                cout << "=";
            } else {
                cout << ",";
            }
        }
        cout << teams[T-1].id << endl;
    }
}