#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> Q;

int main() {
	int m, t, p, r;

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

		vector<Q> krank(t);

		for (int i = 0; i < t; i++) {
			krank[i] = Q(0, P(0, i + 1));
		}

		vector< vector<int> > wa(t, vector<int>(p, 0));

		int mm, tt, pp, jj;

		for (int i = 0; i < r; i++) {
			cin >> mm >> tt >> pp >> jj;
			if (jj == 0) {
				krank[tt - 1].first++;
				(krank[tt - 1].second).first -= mm;
				(krank[tt - 1].second).first -= 20 * wa[tt - 1][pp - 1];
			}
			else {
				wa[tt - 1][pp - 1]++;
			}
		}

		sort(krank.begin(), krank.end(), greater<Q>());

		cout << (krank[0].second).second;
		for (int i = 1; i < t; i++) {
			if (krank[i].first == krank[i - 1].first) {
				if ((krank[i].second).first == (krank[i - 1].second).first) {
					cout << '=' << (krank[i].second).second;
				}
				else {
					cout << ',' << (krank[i].second).second;
				}
			}
			else {
				cout << ',' << (krank[i].second).second;
			}
		}
		cout << endl;

	}

	return 0;
}
