#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct D{int n,s,t,p[15];}D;
D team[55];
int M,T,P,R,i,m,t,p,j;

int cmp(const void *a,const void*b)
{
	D x=(*(D*)a),y=(*(D*)b);
	if(x.s==y.s&&x.t==y.t)return y.n-x.n;
	if(x.s==y.s)return x.t-y.t;
	return y.s-x.s;
}

int main()
{
	for(;scanf("%d%d%d%d",&M,&T,&P,&R),M;)
	{
		memset(team,0,sizeof(team));
		for(i=0;i<T;i++)team[i].n=i+1;
		for(i=0;i<R;i++)
		{
			scanf("%d%d%d%d",&m,&t,&p,&j);
			if(j==0)
			{
				team[t-1].s++;
				team[t-1].t+=m+team[t-1].p[p]*20;
			}
			else
			{
				team[t-1].p[p]++;
			}
		}
		qsort(team,T,sizeof(D),cmp);
		for(i=0;i<T;i++)
			printf("%s%d%s",i==0?"":team[i-1].s==team[i].s&&team[i-1].t==team[i].t?"=":",",team[i].n,i==T-1?"\n":"");
	}
	return 0;
}