#include <iostream>
#include <algorithm>
#define INF 1000000
using namespace std;

bool flag[51];
int M,T,P,R;

bool check(){
	for(int i=1;i<=T;i++)
		if(flag[i])
			return true;
	return false;
}

int main(void){
	while(cin >> M >> T >> P >> R,M|T|P|R){
		for(int i=1;i<=T;i++)
			flag[i]=true;
		int cor[51]={0};
		int time[51]={0};
		int pe[51][11]={0};
		int m,t,p,j;
		for(int i=0;i<R;i++){
			cin >> m >> t >> p >> j;
			if(j){
				pe[t][p]++;
			}else{
				cor[t]++;
				time[t]+=m;
				time[t]+=pe[t][p]*20;
			}
		}
		int o=0;
		while(check()){
			cout << (o? ",":"");
			o++;
			int correct=0,less=INF;
			for(int i=T;i>=1;i--){
				if(!flag[i])
					continue;
				if(cor[i]>correct)
					correct=cor[i],less=time[i];
				else if(correct==cor[i]&&less>time[i])
					less=time[i];
			}
			int d=0;
			for(int i=T;i>=1;i--){
				if(!flag[i])
					continue;
				if(correct==cor[i]&&time[i]==less)
					cout << (d?"=":"") << i,d++,flag[i]=false;
			}
		}
		cout << endl;
	}
	return 0;
}