#include <iostream>
#include <algorithm>
#define REP(i, a, n) for(int i = (a); i <= (n); i++)
using namespace std;
typedef pair<int, int> PII;

int M, T, P, R, m, t, p, j, q[51][11];
PII s[51];

int main(void) {
  while(cin >> M >> T >> P >> R, M || T || P || R) {
    REP(i, 1, T) {
      s[i] = PII(P, 0);
      REP(j, 1, P) q[i][j] = 0;
    }

    REP(i, 1, R) {
      cin >> m >> t >> p >> j;
      if(j == 0) {
        if(q[t][p] >= 0) {
          s[t].first--;
          s[t].second += q[t][p] * 20 + m;
        }
      } else {
        q[t][p]++;
      }
    }

    REP(i, 1, T) {
      s[i].first = s[i].first * 100000000 + s[i].second;
      s[i].second = T - i;
    }
    sort(s + 1, s + T + 1);
    REP(i, 1, T) {
      cout << (T - s[i].second);
      if(i < T) cout << (s[i].first == s[i + 1].first ? '=' : ',');
    }
    cout << endl;
  }
}