#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <set>
#include <map>
#define INF 100000
using namespace std;

struct st{
    int ac;
    int wa;
};


int main(){
    for(;;){
        int M,T,P,R;
        cin >> M >>T>>P>>R;
        if (M==0 and R ==0) break;
        st data[T+1][P+2];
        int ans=0;
        for (int i=1; i<=T; i++) {
            for (int j=1; j<=P+1; j++) {
                data[i][j]={0,0};
            }
        }
        for (int i=0; i < R; i++) {
            int m,t,p,j;
            cin >>m >> t >> p >> j;
            if (j==0) {//ac
                data[t][p].ac = 1;
                data[t][P+1].wa += m;
                data[t][P+1].ac++;
            }else{
                data[t][p].wa++;
            }
        }
        /*for (int i=1; i<=T; i++) {
            for (int j=1; j<=P+1;j++ ) {
                cout << "("<<data[i][j].ac <<","<<data[i][j].wa<<")"<<"|";
            }
            cout << endl;
        }*/
        vector<pair<int,int> > AC(T);
        for (int i=1; i<=T; i++) {
            AC[i-1] = {P+1-data[i][P+1].ac,i};
        }
        sort(AC.begin(), AC.end());
        /*for (int i=0; i<T; i++) {
            cout << AC[i].second << "|";
        }
        cout << endl;
         */
        for (int i=0; i<T; i++) {
            int p=i;
            while (AC[p].first==AC[p+1].first and p+1<T) {
                p++;
            }
            vector<pair<int, int> > time(p-i+1);
            for (int j=i; j<=p; j++) {
                int dis=data[AC[j].second][P+1].wa;
                for (int k = 1; k<P+1; k++) {
                    if (data[AC[j].second][k].ac == 1) {
                        dis += data[AC[j].second][k].wa*20;
                    }
                }
                time[j-i] = {dis, AC[j].second};
            }
            sort(time.begin(), time.end());
            for (int l =0 ;l < p-i+1;l++ ) {
                int s = l;
                if (s+1 >= p-i+1) {
                    cout << time[s].second;
                    ans++;
                    if (ans != T) {
                        cout << ",";
                    }
                }else{
                    while (time[s].first==time[s+1].first and s+1 < p-i+1) {
                        s++;
                    }
                    if (s-l>=1) {
                        for (int u =0; u<=s-l; u++) {
                            cout << time[s-u].second;
                            ans++;
                            if (u==s-l and ans != T) {
                                cout << ",";
                            }else{
                                if (ans != T) {
                                    cout << "=";
                                }
                            }
                        }
                    }else{
                        cout << time[s].second;
                        ans++;
                        if (ans != T) {
                            cout << ",";
                        }
                    }
                }
                l = s;
            }
            i=p;
        }
        cout << endl;
    }
}

Measured memory_bytes: 1204