#include<bits/stdc++.h>
using namespace std;

int main() {
	int m, t, p, r;
	while (cin >> m >> t >> p >> r) {
		if (m == 0) break;
		vector<pair<int, int>> cnt(55);
		for (int i = 0; i < t; i++) {
			cnt[i] = make_pair(0, i);
		}
		int time[55] = {};
		int pena[55][20] = {};
		for (int i = 0; i < r; i++) {
			int a, b, c, d;
			cin >> a >> b >> c >> d;
			b--;
			if (d == 0) {
				time[b] += a + 20 * pena[b][c];
				cnt[b].first++;
			}
			else {
				pena[b][c]++;
			}
		}
		sort(cnt.begin(), cnt.end());
		reverse(cnt.begin(), cnt.end());
		vector<vector<pair<int,int>>> ac(15);
		for (int i = 0; i < t; i++) {
			ac[cnt[i].first].push_back(make_pair(time[cnt[i].second],-cnt[i].second));
		}
		bool win = true;
		for (int i = p; i >= 0; i--) {
			if (ac[i].empty()) continue;
			sort(ac[i].begin(), ac[i].end());
			if (!win) cout << ",";
			if (win) win = false;
			cout << -ac[i][0].second +1;
			
			for (int j = 1; j < ac[i].size(); j++) {
				if (ac[i][j - 1].first == ac[i][j].first) {
					cout << "=";
				}
				else cout << ",";
				cout << -ac[i][j].second + 1;
			}
		}
		cout << endl;
	}
}
