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

typedef struct {
    int m;
    int t;
    int p;
    int j;
} LOG;

typedef struct {
    int team;
    int score;  // 問題数*10000 + 5000 - 合計(提出時間 + ペナルティ) 
} TEAM;




int comp(const void *a, const void *b)
{
    int score;
    
    score = (*(TEAM *)b).score - (*(TEAM *)a).score;

    if (score != 0){
        return (score);
    }
    return ((*(TEAM *)b).team - (*(TEAM *)a).team);
}


int main(void)
{
    int M, T, P, R;
    LOG log[2000];
    TEAM team[50];
    int i, k;
    
    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 = i + 1;
            team[i].score = 90000;
        }
        
        for (i = 0; i < R; i++){
            scanf("%d%d%d%d", &log[i].m, &log[i].t, &log[i].p, &log[i].j);
            if (log[i].j == 0){
                team[log[i].t - 1].score += 100000;
                team[log[i].t - 1].score -= log[i].m;
                for (k = i - 1; k >= 0; k--){
                    if (log[k].t == log[i].t && log[k].p == log[i].p && log[k].j != 0){
                        team[log[i].t - 1].score -= 20;
                    }
                }
            }
        }
        
        qsort(team, T, sizeof(TEAM), comp);
        
        for (i = 0; i < T; i++){
            printf("%d", team[i].team);
            if (i < T - 1){
                if (team[i].score > team[i + 1].score){
                    printf(",");
                }
                else {
                    printf("=");
                }
            }
        }
        printf("\n");
    }
    return (0);
}

