#include <bits/stdc++.h>

using namespace std;

using pii = pair<int, int>;

int main()
{
    while (true) {
        int M, T, P, R;
        cin >> M >> T >> P >> R;
        if (M == 0 and T == 0 and P == 0 and R == 0) {
            break;
        }
        vector<vector<int>> wa(T, vector<int>(P, 0));
        vector<pair<pii, int>> score(T, make_pair(make_pair(P, 0), 0));
        for (int i = 0; i < T; i++) {
            score[i].second = T - i;
        }
        for (int i = 0; i < R; i++) {
            int m, t, p, j;
            cin >> m >> t >> p >> j;
            t--, p--;
            if (j == 0) {
                score[t].first.first--;
                score[t].first.second += (m + wa[t][p] * 20);
            } else {
                wa[t][p]++;
            }
        }
        sort(score.begin(), score.end());
        for (int i = 0; i < T; i++) {
            if (i > 0) {
                if (score[i - 1].first.first == score[i].first.first and score[i - 1].first.second == score[i].first.second) {
                    cout << '=';
                } else {
                    cout << ',';
                }
            }
            cout << T - score[i].second + 1;
        }
        cout << endl;
    }
    return 0;
}