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++: // tsukasa_diary's programing contest code template
#include <bits/stdc++.h>
using namespace std;
// define
#define for_(i,a,b) for(int i=a;i<b;++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()
// typedef
typedef long long lint;
typedef double Double;
typedef pair<int, int> pii;
//
typedef vector< int > Array;
typedef vector< Array > Matrix;
typedef vector< Double > DArray;
typedef vector< DArray > DMatrix;
typedef vector< string > SArray;
typedef vector< pii > PArray;
// popcount
inline int POPCNT(int _x) { return __builtin_popcount(_x); }
inline int POPCNT(lint _x) { return __builtin_popcountll(_x); }
// inf
const int iINF = 1L << 30;
const lint lINF = 1LL << 60;
// eps
Double EPS = 1e-9;
// in range
inline bool in_range(int _v, int _mx, int _mi) { return _mi <= _v && _v < _mx; }
inline bool in_range(Double _v, Double _mi, Double _mx) { return -EPS < _v - _mi && _v - _mx < EPS; }
inline bool in_range(int _x, int _y, int _W, int _H) { return 0 <= _x && _x < _W && 0 <= _y && _y < _H; }
// neighbor clockwise
const int DX[4] = {0,1,0,-1}, DY[4] = {-1,0,1,0};
const int DX_[8] = {0,1,1,1,0,-1,-1,-1}, DY_[8] = {-1,-1,0,1,1,1,0,-1};

int M, T, P, R;

struct Team {
	int correct, time, id;
	Team(int _c, int _t, int _i) : correct(_c), time(_t), id(_i) {}
};

bool operator > (const Team& a, const Team& b) {
	if (a.correct == b.correct) {
		if (a.time == b.time) {
			return a.id > b.id;
		}
		return a.time < b.time;
	}
	return a.correct > b.correct;
}

bool operator < (const Team& a, const Team& b) {
	return b > a;
}

bool eq(const Team& a, const Team& b) {
	return a.correct == b.correct && a.time == b.time;
}

void solve() {
	Matrix penalty(T, Array(P, 0));
	vector< vector< bool > > correct(T, vector< bool >(P, false));
	
	vector< Team > vt(T, Team(0, 0, 0));
	for_(i,0,T) vt[i].id = i + 1;
	
	for_(i,0,R) {
		int m, t, p, j; cin >> m >> t >> p >> j;
		--t; --p;
		
		if (correct[t][p]) continue;
		
		if (j == 0) {
			++vt[t].correct;
			vt[t].time += penalty[t][p] + m;
			correct[t][p] = true;
		} else {
			penalty[t][p] += 20;
		}
	}
	
	sort(allof(vt), greater<Team>());
	
	for_(i,0,T) {
		if (i > 0) {
			if (eq(vt[i - 1], vt[i])) cout << "=";
			else cout << ",";
		}
		
		cout << vt[i].id;
	}
	cout << endl;
}

int main() {
	while (cin >> M >> T >> P >> R, M) {
		solve();
	}
	return 0;
}

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

using namespace std;

int main() {
    while(true) {
        int M, T, P, R;
        cin >> M >> T >> P >> R;

        if(M == 0 && T==0 && P == 0 && R == 0) return 0;

        int m, t, p, j;
        int result[T];
        fill(result, result + T, 0);
        int time[T];
        fill(time, time + T, 0);
        int failure[T][P];
        fill(failure[0], failure[T] + P, 0);
        for (int submit = 0; submit < R; submit++) {
            cin >> m >> t >> p >> j;
            if (j == 0) {
                result[t - 1] += 1;
                time[t - 1] += m + failure[t - 1][p-1] * 20;
            } else {
                ++failure[t - 1][p-1];
            }
        }

        bool done[T];
        fill(done, done + T, false);
        int prevPoint, prevTime;
        for (int count = 0; count < T; count++) {
            int maxPoint = -1;
            int maxTeam = 0;
            int minTime = 100000;
            for (int i = T - 1; i >= 0; i--) {
                if (done[i]) continue;
                if (maxPoint < result[i]) {
                    maxPoint = result[i];
                    maxTeam = i + 1;
                    minTime = time[i];
                } else if (maxPoint == result[i]) {
                    if (minTime > time[i]) {
                        minTime = time[i];
                        maxTeam = i + 1;
                    }
                }
            }
            minTime = time[maxTeam - 1];
            if (count != 0) {
                if (maxPoint == prevPoint && minTime == prevTime) cout << "=";
                else cout << ",";
            }
            cout << maxTeam;
            done[maxTeam - 1] = true;
            prevPoint = maxPoint;
            prevTime = minTime;
        }
        cout << endl;
    }
}