#include <bits/stdc++.h>

using namespace std;

int main()
{
    int M, T, P, R;
    
    while (scanf("%d %d %d %d", &M, &T, &P, &R) && M){
        vector<pair<pair<int, int>, int> > record(T);
        int wa[64][16] = {0};
        
        for (int i = 0; i < T; i++) record[i].second = -(i + 1);
        
        for (int i = 0; i < R; i++){
            int m, t, p, j;
            scanf("%d %d %d %d", &m, &t, &p, &j);
            if (j) wa[t - 1][p] += 20;
            else {
                record[t - 1].first.first--;
                record[t - 1].first.second += m + wa[t - 1][p];
            }
        }
        
        sort(record.begin(), record.end());
        
        for (int i = 0; i < T; i++){
            printf("%d", -record[i].second);
            if (i + 1 < T && record[i].first == record[i + 1].first) printf("=");
            else if (i + 1 < T) printf(",");
            else printf("\n");
        }
    }
    
    return (0);
}