#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

using namespace std;

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;

using namespace std;

struct data {
    int time, team, number, judge;
};

int penalties[51][11];
int times[51];
int point[51];
int ranking[51];

int main()
{
    int M, T, P, R;

    while (cin >> M >> T >> P >> R, M|T|P|R) {
        fill_n((int *)penalties, 51 * 11, 0);
        fill_n((int *)times, 51, 0);
        fill_n((int *)point, 51, 0);
        for (int i = 1; i <= T; i++) ranking[i] = i;
        int m, t, p, j;
        for (int i = 0; i < R; i++) {
            cin >> m >> t >> p >> j;
            if (j == 0) {
                point[t]++;
                times[t] += m + penalties[t][p];
            } else {
                penalties[t][p] += 20;
            }
        }
        for (int i = 1; i <= T; i++) {
            for (int j = i; j <= T; j++) {
                if (point[i] < point[j]) {
                    int a = ranking[i];
                    ranking[i] = ranking[j];
                    ranking[j] = a;
                    a = point[i];
                    point[i] = point[j];
                    point[j] = a;
                    a = times[i];
                    times[i] = times[j];
                    times[j] = a;
                }
            }
        }
        for (int i = 1; i <= T; i++) {
            for (int j = i; j <= T; j++) {
                if (point[i] == point[j]) {
                    if (times[i] > times[j]) {
                        int a = ranking[i];
                        ranking[i] = ranking[j];
                        ranking[j] = a;
                        a = point[i];
                        point[i] = point[j];
                        point[j] = a;
                        a = times[i];
                        times[i] = times[j];
                        times[j] = a;
                    }
                    if (times[i] == times[j]) {
                        if (ranking[i] < ranking[j]) {
                            int a = ranking[i];
                            ranking[i] = ranking[j];
                            ranking[j] = a;
                            a = point[i];
                            point[i] = point[j];
                            point[j] = a;
                            a = times[i];
                            times[i] = times[j];
                            times[j] = a;
                        }
                    }
                }
            }
        }
        for (int i = 1; i <= T; i++) {
            cout << ranking[i];
            if (i+1 <= T) {
                if (point[i] == point[i+1] && times[i] == times[i+1]) {
                    cout << "=";
                } else {
                    cout << ",";
                }
            }
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 1164