import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;
 
bool solve() {
    int M, T, P, R; readf("%d %d %d %d\n", &M, &T, &P, &R);
    if (M == 0 && T == 0 && P == 0 && R == 0) return false;
    struct Team {
        int id;
        int ac;
        int penalty;
    }
    Team[] X = new Team[T];
    for (int i = 0; i < T; i++) X[i].id = i + 1;
    int[][] W = new int[][](T, P); // WA Count
    for (int i = 0; i < R; i++) {
        int m, t, p, j; readf("%d %d %d %d\n", &m, &t, &p, &j);
        t--; p--;
        if (j == 0) {
            X[t].ac++;
            X[t].penalty += m + W[t][p] * 20;
        } else {
            W[t][p]++;
        }
    }
    bool comp(in Team a, in Team b) {
        if (a.ac == b.ac) {
            if (a.penalty == b.penalty) {
                return a.id > b.id;
            } else {
                return a.penalty < b.penalty;
            }
        } else {
            return a.ac > b.ac;
        }
    }
    X = X.sort!(comp).array;
    printf("%d", X[0].id);
    for (int i = 1; i < T; i++) {
        if (X[i - 1].ac == X[i].ac && X[i - 1].penalty == X[i].penalty) {
            printf("=");
        } else {
            printf(",");
        }
        printf("%d", X[i].id);
    }
    printf("\n");
    return true;
}

void main() {
    while (solve()) {}
}