#include <stdio.h>
#include <memory.h>
struct Data{
	int team,solve,time,wrong[10];
};
int main(void){
	struct Data D[50];
	int M,T,P,R,m,t,p,j,i;
	while(1){
		scanf("%d %d %d %d",&M,&T,&P,&R);
		if(!M)
			break;
		memset(D,0,sizeof(D));
		for(i=0;i<T;i++)
			D[i].team=i+1;
		for(i=0;i<R;i++){
			scanf("%d %d %d %d",&m,&t,&p,&j);
			if(j){
				D[t-1].wrong[p-1]++;
			}
			else{
				D[t-1].solve++;
				D[t-1].time+=m+20*D[t-1].wrong[p-1];
			}
		}
		for(i=0;i<T-1;i++){
			for(j=T-1;j>i;j--){
				if(D[j-1].solve<D[j].solve||D[j-1].solve==D[j].solve&&D[j-1].time>D[j].time||D[j-1].solve==D[j].solve&&D[j-1].time==D[j].time&&D[j-1].team<D[j].team){
					struct Data tmp=D[j-1];
					D[j-1]=D[j];
					D[j]=tmp;
				}
			}
		}
		for(i=0;i<T-1;i++){
			printf("%d",D[i].team);
			if(D[i].solve==D[i+1].solve&&D[i].time==D[i+1].time)
				printf("=");
			else
				printf(",");
		}
		printf("%d\n",D[i].team);
	}
	return 0;
}