#include<iostream>
#include<map>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<unordered_map>
using namespace std;

struct team {
	int seikai = 0, matigai[10]{}, time = 0, ID;
};
bool operator <(team a, team b) {
	if (a.seikai != b.seikai)return a.seikai > b.seikai;
	else if (a.time != b.time)return a.time < b.time;
	return a.ID > b.ID;
}
int main() {
	int a, b, c, d;
	while (cin >> a >> b >> c >> d, a || b || c || d) {
		team f[51]{};
		f[0].time = f[0].seikai= 1 << 29;
		for (int i = 0; i < b; i++) {
			f[i+1].ID = i + 1;
		}
		for (int e = 0; e < d; e++) {
			int g, h, i, j; scanf("%d%d%d%d", &g, &h, &i, &j); i--;
			if (j) {
				f[h].matigai[i]++;
			}
			else {
				f[h].seikai++;
				f[h].time += f[h].matigai[i] * 20 + g;
			}
		}
		sort(f+1, f + b+1);
		for (int i = 1; i < b; i++) {
			cout << f[i].ID;
			if (f[i].seikai == f[i + 1].seikai&&f[i].time == f[i + 1].time)cout << '=';
			else cout << ',';
		}
		cout <<f[b].ID<< endl;
	}
}