#include<iostream>
#include<string.h>
using namespace std;

const int INF=5000000;

int data[51][12];

int main(){
	int M,T,P,R;
	while(cin>>M>>T>>P>>R && M){
		fill((int*)data,(int*)(data+12),0);
		for(int i=0;i<R;i++){
			int m,t,p,j;
			cin>>m>>t>>p>>j;
			if(j==0){
				data[t][0]++;
				data[t][11]+=m+data[t][p]*20;
			}
			else data[t][p]++;
		}
		int prev[2]={INF,0};
		for(int i=0;i<T;i++){
			int ans=0;
			int now[2]={0,INF};
			for(int j=T;j>=0;j--){
				if(data[j][0]>now[0]){
					now[0]=data[j][0];
					now[1]=data[j][11];
					ans=j;
				}
				else if(data[j][0]==now[0] && data[j][11]<now[1]){
					now[1]=data[j][11];
					ans=j;
				}
			}
			if(i){
				if(memcmp(now,prev,sizeof(now))==0)cout<<"=";
				else cout<<",";
			}
			cout<<ans;
			memcpy(prev,now,sizeof(now));
			data[ans][0]=-1;
		}
		cout<<endl;
	}
}