#include <bits/stdc++.h>

using namespace std;

int main()
{
	int M, T, P, R;

	while (scanf("%d %d %d %d", &M, &T, &P, &R), M){
		int m, t, p, j;
		//score, penalty, team
		vector<pair<int, pair<int, int> > > table(T);
		int wa[64][16] = {0};

		for (int i = 0; i < T; i++){
			table[i].second.second = i + 1;
		}

		for (int i = 0; i < R; i++){
			scanf("%d %d %d %d", &m, &t, &p, &j);

			if (j){
				wa[t - 1][p] += 20;
			}
			else {
				table[t - 1].first++;
				table[t - 1].second.first -= wa[t - 1][p];
				table[t - 1].second.first -= m;
			}
		}

		sort(table.begin(), table.end(), greater<pair<int, pair<int, int> > >());

		for (int i = 0; i < table.size(); i++){
			cout << table[i].second.second;

			if (table[i].second.first == table[i + 1].second.first && i < T - 1){
				cout << '=';
			}
			else if (i < T - 1){
				cout << ',';
			}
			else {
				cout << endl;
			}
		}
	}


	return (0);
}