#include <bits/stdc++.h>

#define REP(i, n) for(int i = 0; i < (int) (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define INF 1e9

using namespace std;

struct team{
  int id;
  array<int, 10> penalty;
  int correct;
  int score;
  team(int i) : id(i), penalty({0}), correct(0), score(0) {}
  bool operator<(const team &x)const{
    if(correct < x.correct) return true;
    if(correct > x.correct) return false;
    if(score > x.score) return true;
    if(score < x.score) return false;
    if(id < x.id) return true;
    return false;
  }
  bool operator==(const team &x)const{
    if(correct == x.correct and score == x.score) return true;
    return false;
  }
};

int main(){
  int m, t, r, p;
  while(cin >> m >> t >> p >> r and m + t + p + r){
    vector<team> teams;
    REP(i, t) teams.emplace_back(i+1);
    REP(i, r){
      int mk, tk, pk, jk;
      cin >> mk >> tk >> pk >> jk;
      tk--; pk--;
      if(jk) teams[tk].penalty[pk]++;
      if(!jk) { teams[tk].correct++; teams[tk].score += teams[tk].penalty[pk] * 20 + mk; }
    }
    sort(ALL(teams));
    reverse(ALL(teams));
    REP(i, teams.size()){
      cout << teams[i].id;
      if(i < teams.size()-1) cout << (teams[i] == teams[i+1] ? "=" : ",");
    }
    cout << endl;
  }
  return 0;
}