#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
struct square {
	int s, t, u; // solved, time, team
	square() : s(0), t(0), u(0) {}
	square(int p, int q, int r) : s(p), t(q), u(r) {}
};
bool operator==(square s1, square s2) { return s1.s == s2.s && s1.t == s2.t; }
bool operator!=(square s1, square s2) { return !(s1 == s2); }
bool operator<(square s1, square s2) {
	if(s1.s != s2.s) return s1.s > s2.s;
	if(s1.t != s2.t) return s1.t < s2.t;
	return s1.u > s2.u;
}
int T, N, P, Q, t, n, p, q;
int main() {
	while(scanf("%d%d%d%d", &T, &N, &P, &Q), N) {
		square d[50]; int v[50][10]; memset(v, 0, sizeof(v));
		for(int i = 0; i < N; i++) d[i] = square(0, 0, i + 1);
		for(int i = 0; i < Q; i++) {
			scanf("%d%d%d%d", &t, &n, &p, &q);
			if(q != 0) v[n - 1][p - 1]++;
			else d[n - 1].s++, d[n - 1].t += t + v[n - 1][p - 1] * 20;
		}
		sort(d, d + N);
		printf("%d", d[0].u);
		for(int i = 1; i < N; i++) {
			if(d[i - 1] != d[i]) printf(",%d", d[i].u);
			else printf("=%d", d[i].u);
		}
		printf("\n");
	}
}