#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>

using namespace std;
vector<pair<int , pair<int, int> > > score(51);
int wrongans[51];

int main()
{
	int M, T, P, R;
	while(1){
		cin >> M >> T >> P >> R;
		if(M == 0 && T == 0 && P == 0 && R == 0) break;
		for(int i = 1; i <= T; i++){
			score[i].first = 0;
			(score[i].second).first = 0;
			(score[i].second).second = -i;
		}
		int wrongans[51][11] = {0};
		int m, t, p, j;
		for(int i = 0; i < R; i++){
			cin >> m >> t >> p >> j;
			if(j == 0){
				score[t].first--;
				(score[t].second).first += m + (20 * wrongans[t][p]);
			} else {
				wrongans[t][p]++;
			}
		}
		sort(score.begin() + 1, score.begin() + T + 1);
		for(int i = 1; i <= T; i++){
			cout << -(score[i].second).second;
			if(i == T) cout << endl;
			else if(score[i + 1].first == score[i].first && (score[i + 1].second).first == (score[i].second).first) cout << '=';
			else cout << ',';
		}
	}
	return 0;
}