#include <stdio.h>
#include <stdlib.h>

typedef struct{
	int id;
	int score;
	int time;
	int wrong[10];
}team;

int comp(const void* c1, const void*c2){
	team* t1 = (team*)c1;
	team* t2 = (team*)c2;
	if(t1->score!=t2->score){
		return t2->score - t1->score;
	}else if(t1->time!=t2->time){
		return t1->time - t2->time;
	}else{
		return t2->id - t1->id;
	}
}

int M,T,P,R;
team teams[50];

int main(void){
	int i,j;
	while(scanf("%d %d %d %d",&M,&T,&P,&R),M|T|P|R){
		for(i=0;i<T;i++){
			teams[i].id=i+1;
			teams[i].score=0;
			teams[i].time=0;
			for(j=0;j<10;j++){
				teams[i].wrong[j]=0;
			}
		}
		int m,t,p,j;
		for(i=0;i<R;i++){
			scanf("%d %d %d %d",&m,&t,&p,&j);
			if(j==0){
				teams[t-1].score++;
				teams[t-1].time=m+20*(teams[t-1].wrong[p-1]);
			}else{
				teams[t-1].wrong[p-1]++;
			}
		}
		qsort(teams,T,sizeof(team),comp);
		for(i=0;i<T;i++){
			if(i==0){
				printf("%d",teams[i].id);
			}else{
				if(teams[i-1].score==teams[i].score&&teams[i-1].time==teams[i].time){
					printf("=%d",teams[i].id);
				}else{
					printf(",%d",teams[i].id);
				}
			}
		}
		printf("\n");
	}
	return 0;
}