#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int m, t, p, r;
    while (cin >> m >> t >> p >> r && m){
        vector<pair<P, int> > a(t);
        REP(i,t) a[i].second = -(i+1);
        int w[50][10] = {};
        while (r--){
            int x, y, z, j;
            cin >> z >> x >> y >> j;
            x--;
            y--;
            if (j != 0){
                w[x][y]++;
            }else{
                a[x].first.first--;
                a[x].first.second += z + 20 * w[x][y];
            }
        }
        sort(a.begin(), a.end());
        cout << -a[0].second;
        FOR(i,1,t-1){
            if (a[i].first == a[i-1].first) cout << "=";
            else cout << ",";
            cout << -a[i].second;
        }
        cout << endl;
    }

    return 0;
}