#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
int team[51],wrong[51][11],time[51],count[51];
int main(void){
    int M,T,P,R,i,o,m,t,p,j,temp;
    while(1){
        for(i=0;i<51;i++)
            team[i]=time[i]=count[i]=0;
        memset(wrong,0,sizeof(wrong));
        scanf("%d %d %d %d",&M,&T,&P,&R);
        if(!(M+T+P+R))
            break;
        for(o=T;o>=1;o--)
            team[T-o+1]=o;
        for(i=0;i<R;i++){
            scanf("%d %d %d %d",&m,&t,&p,&j);
            if(j)
                wrong[t][p]++;
            else{
                if(wrong[t][p])
                    time[t]+=wrong[t][p]*20;
                time[t]+=m;
                count[t]++;
            }
        }
        for(i=2;i<=T;i++){
            temp=team[i];
            for(o=i;o>1;o--){
                if(count[temp] > count[team[o-1]])
                    team[o]=team[o-1];
                else if(count[temp] == count[team[o-1]] && time[temp] < time[team[o-1]])
                    team[o]=team[o-1];
                else
                    break;
            }
            team[o]=temp;
        }
        for(i=1;i<=T;i++)
            printf("%d%s",team[i],i==T?"\n":(count[team[i]]==count[team[i+1]] && time[team[i]]==time[team[i+1]]?"=":","));
    }
    return 0;
}