#include <stdio.h>
typedef struct{
    int team_num;
    int num;
    int min;
    int fault;
    int rank;
}TEAM;

int main(){
    TEAM team[50],tmp;
    int i,j,rank=1;
    int m,t,p,k;
    int M,T,P,R;
    while(1){
    scanf("%d %d %d %d", &M, &T, &P, &R);
    if(M==0&&T==0&&P==0&&R==0) break;
    for(i=0;i<T;i++){
        team[i].team_num = i+1;
        team[i].num      = 0;
        team[i].min      = 0;
        team[i].fault    = 0;
        team[i].rank     = 0;
    }
    for(i=0;i<R;i++){
        scanf("%d %d %d %d", &m, &t, &p, &k);
        if(m>M) continue;
        if(k==0){
            team[t-1].num++;
            team[t-1].min += m;
            team[t-1].min += team[t-1].fault*20;
            team[t-1].fault = 0;
        }
        else team[t-1].fault++;
    }

    for(i=0;i<T;i++){
        for(j=i+1;j<T;j++){
            if(team[i].num < team[j].num){
                tmp     = team[i];
                team[i] = team[j];
                team[j] = tmp;
            }
            else if(team[i].num == team[j].num){
                if(team[i].min > team[j].min){
                    tmp     = team[i];
                    team[i] = team[j];
                    team[j] = tmp;
                }
                else if((team[i].min == team[j].min)&&(team[i].team_num < team[j].team_num)){
                    tmp     = team[i];
                    team[i] = team[j];
                    team[j] = tmp;
                }
            }
        }
    }
    for(i=0;i<T;i++){
        team[i].rank = rank;
        if(i!=T-1){
            if(team[i].num != team[i+1].num || team[i].min != team[i+1].min) rank++;
        }
    }
    printf("%d",team[0].team_num);
    for(i=1;i<T;i++){
        if(team[i].rank == team[i-1].rank) printf("=");
        else                               printf(",");
        printf("%d",team[i].team_num);
    }
    printf("\n");
    }
    return 0;
}