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

typedef struct {
	int id;
	int score;
	int penalty;
} team_t;

int compTeam(const void* x,const void* y) {
	const team_t* a=(const team_t*)x;
	const team_t* b=(const team_t*)y;
	if((a->score)<(b->score))return 1;
	if((a->score)>(b->score))return -1;
	if((a->penalty)>(b->penalty))return 1;
	if((a->penalty)<(b->penalty))return -1;
	if((a->id)<(b->id))return 1;
	if((a->id)>(b->id))return -1;
	return 0;
}

team_t teams[50];
int solved[50][10];

int main(void) {
	int M,T,P,R;
	while(scanf("%d%d%d%d",&M,&T,&P,&R)==4 && (M|T|P|R)!=0) {
		int i,j;
		memset(teams,0,sizeof(teams));
		memset(solved,0,sizeof(solved));
		for(i=0;i<R;i++) {
			int m,t,p,jj;
			scanf("%d%d%d%d",&m,&t,&p,&jj);
			if(solved[t-1][p-1]<=0) {
				if(jj==0)solved[t-1][p-1]=-solved[t-1][p-1]*20+m+1;
				else solved[t-1][p-1]--;
			}
		}
		for(i=0;i<T;i++) {
			teams[i].id=i+1;
			for(j=0;j<P;j++) {
				if(solved[i][j]>0) {
					teams[i].score++;
					teams[i].penalty+=solved[i][j]-1;
				}
			}
		}
		qsort(teams,T,sizeof(team_t),compTeam);
		printf("%d",teams[0].id);
		for(i=1;i<T;i++) {
			if(teams[i-1].score==teams[i].score &&
			teams[i-1].penalty==teams[i].penalty) {
				putchar('=');
			} else {
				putchar(',');
			}
			printf("%d",teams[i].id);
		}
		putchar('\n');
	}
	return 0;
}