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 <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    int M, T, P, R;
    while(cin >> M >> T >> P >> R, M || T || P || R) {
        int m, t, p, j;

        // board[team][problem] := judge
        int board[60][15] = {};
        int probnum[60] = {};
        int acctime[60] = {};

        rep(i,0,R) {
            cin >> m >> t >> p >> j;
            t--;
            if(j != 0) {
                board[t][p]++;
            }
            else {
                acctime[t] -= m + 20 * board[t][p];
                probnum[t]++;
            }
        }

        vector< pair< pii, int > > pp;
        rep(i,0,T) pp.pb(make_pair( make_pair(probnum[i], acctime[i]), i+1) );
        pii prev = pii(-1, -1);
        sort(pp.begin(), pp.end());
        reverse(pp.begin(), pp.end());


        rep(i,0,T) {
            if(prev == pii(-1, -1)) {
                prev = pp[i].fr;
                printf("%lld", pp[i].sc);
            }
            else if(prev == pp[i].fr) {
                printf("=%lld", pp[i].sc);
            }
            else if(prev != pp[i].fr) {
                printf(",%lld", pp[i].sc);
                prev = pp[i].fr;
            }
        }
        cout << endl;
    }
    return 0;
}

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

using namespace std;

typedef pair<long, int> pr; // first: pts, second: team number;

int penalty[50][10]; // [team][problem number]
pr pts[50];
priority_queue<int> list;
int m, t, p, r;

int printout(int n, long pre) {
	if (n < t && pre == pts[n].first) {
		list.push(pts[n].second);
		return printout(n+1, pre);
	} else {
		int size = list.size();
		if (size == 0) return 1;
		while (true) {
			cout << list.top();
			list.pop();
			if (list.empty()) break;
			cout << "=";
		}
		return size;
	}

	cout << "ERR" << endl;
	return 0;
}

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

		for (int i = 0; i < t; ++i) {
			pts[i].second = i+1;
			pts[i].first = 0;
			for (int j = 0; j < p; ++j)
				penalty[i][j] = 0;
		}
		for (int i = 0; i < r; ++i) {
			int a, b, c, d;
			cin >> a >> b >> c >> d;
			if (d == 0) {
				pts[b-1].first += -10000 + a + penalty[b-1][c-1];
			} else {
				penalty[b-1][c-1] += 20;
			}
		}

		sort(pts, pts + t);
		int i = 0;
		while (true) {
			i += printout(i, pts[i].first);
			if (i >= t)
				break;
			cout << ",";
		}
		cout << endl;
	}

	return 0;
}