#include <iostream>
#include <sstream>
#include <fstream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <list>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <climits>
using namespace std;

struct score {
	long teamNum;
	long accepted;
	long time;
	vector<long> miss;
	bool operator==(score s) const {
		return this->accepted == s.accepted && this->time == s.time;
	};
	bool operator<(score s) const {
		return this->accepted != s.accepted ? this->accepted > s.accepted : (this->time != s.time ? this->time < s.time : this->teamNum > s.teamNum);
	};
};

int main() {
	while(1){
		int M, T, P, R;
		cin >> M >> T >> P >> R;
		
		if(!M && !T && !P && !R) break;
		
		score *sc = new score[1+T];
		for(int i = 1; i <= T; i++){
			sc[i].teamNum = i;
			sc[i].accepted = sc[i].time = 0;
		}
		for(int i = 0; i < R; i++){
			int m, t, p, r;
			cin >> m >> t >> p >> r;
			
			if(r){
				sc[t].miss.push_back(p);
			}else{
				sc[t].accepted++;
				sc[t].time += m + 20 * count(sc[t].miss.begin(), sc[t].miss.end(), p);
			}
		}
		
		sort(&sc[1], &sc[1+T]);
		for(int i = 1; i <= T; i++){
			cout << sc[i].teamNum << (i==T ? '\n' : (sc[i]==sc[i+1] ? '=' : ','));
		}
	}
	return 0;
}