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

#define PENALTY 20
#define P_MAX 10
#define T_MAX 50

int wa_count[T_MAX][P_MAX], solved[T_MAX], time[T_MAX], t;
int teams[T_MAX], comp_stable = 1;

void init()
{
    int tt, p;

    for(tt = 0; tt < t; tt++)
    {
        solved[tt] = time[tt] = 0;
        teams[tt] = tt;
        for(p = 0; p < P_MAX; p++) wa_count[tt][p] = 0;
    }
}

int comp_team(const void* a, const void* b)
{
    int t = solved[*(int*)b] - solved[*(int*)a];
    t = t ? t : time[*(int*)a] - time[*(int*)b];

    return t ? t : comp_stable ? *(int*)b - *(int*)a : 0;
}

int main(void)
{
    int m, tt, p, r, j;

    while(scanf("%d%d%d%d", &m, &t, &p, &r), m + t + p + r)
    {
        init();

        while(r--)
        {
            scanf("%d%d%d%d", &m, &tt, &p, &j);
            tt--;

            if(j) wa_count[tt][p]++;
            else solved[tt]++, time[tt] += wa_count[tt][p] * PENALTY + m;
        }

        comp_stable = 1;
        qsort(teams, t, sizeof(int), comp_team);

        comp_stable = 0;
        for(tt = 0; tt < t - 1; tt++)
        {
            printf("%d", teams[tt] + 1);
            if(comp_team(&teams[tt], &teams[tt + 1])) printf(",");
            else printf("=");
        }
        printf("%d\n", teams[tt] + 1);
    }

    return 0;
}