#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=l;i<r;i++)

int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

int main(){
	ll t,p,r;
	while(scanf("%*lld%lld%lld%lld",&t,&p,&r),t){
		ll a[60][20]={};
		ll f[60][20]={};
		while(r--){
			ll x,i,j,q;
			scanf("%lld%lld%lld%lld",&x,&i,&j,&q);
			if(q)a[i][j]+=20;
			else{
				a[i][j]+=x;
				f[i][j]=1;
			}
		}
		ll temp[60]={};
		rep(i,1,t+1){
			ll co=0,ti=0;
			rep(j,1,p+1)if(f[i][j]){
				co++;
				ti+=a[i][j];
			}
			temp[i]=co*2700000-ti*60+i;
		}
		sortdown(temp+1,t);
		rep(i,1,t+1){
			printf("%d",temp[i]%60);
			if(i!=t)printf("%c",temp[i]/60==temp[i+1]/60?'=':',');
		}
		puts("");
	}
}
