
#include<stdio.h>

#define MaxT 50
#define MaxP 10

int rank[MaxT];
int time[MaxT];
int correct[MaxT];
int wrong[MaxT][MaxP];

int less(int a, int b) {
    if(correct[a] != correct[b]) return correct[a] < correct[b];
    if(time[a] != time[b]) return time[a] > time[b];
    return a < b;
}

int main(void) {
    int M, T, P, R;
    int m, t, p, j;
    int i, ii;
    while(scanf("%d %d %d %d", &M, &T, &P, &R), M | T | P | R) {
        for(i = 0; i < T; i++) {
            rank[i] = i;
            time[i] = 0;
            correct[i] = 0;
            for(ii = 0; ii < P; ii++) wrong[i][ii] = 0;
        }

        for(i = 0; i < R; i++) {
            scanf("%d %d %d %d", &m, &t, &p, &j);
            t--;
            p--;
            if(j) {
                wrong[t][p]++;
            } else {
                correct[t]++;
                time[t] += m + 20 * wrong[t][p];
            }
        }

        for(i = 0; i < T; i++) {
            for(ii = 0; ii < T - i - 1; ii++) {
                if(less(rank[ii], rank[ii + 1])) {
                    rank[ii] ^= rank[ii + 1];
                    rank[ii + 1] ^= rank[ii];
                    rank[ii] ^= rank[ii + 1];
                }
            }
        }

        printf("%d", rank[0] + 1);
        for(i = 1; i < T; i++) {
            if((correct[rank[i]] == correct[rank[i - 1]]) && (time[rank[i]] == time[rank[i - 1]])) {
                printf("=");
            } else {
                printf(",");
            }
            printf("%d", rank[i] + 1);
        }
        printf("\n");
    }
    return 0;
}