#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;
struct Team{
  int id,m,tm;
  Team():id(0),m(0),tm(0){}
  Team(int i):id(i),m(0),tm(0){}
};

bool operator < (const Team& a, const Team& b){
  return a.m>b.m || (a.m==b.m && a.tm < b.tm) || (a.m==b.m && a.tm==b.tm && a.id > b.id);
}

int mistake[60][20];

int main(){
  int m,t,p,r;
  while(cin>>m>>t>>p>>r,m||t||p||r){
    memset(mistake,0,sizeof(mistake));
    Team tem[60];
    for(int i=0;i<t;++i) tem[i]=Team(i+1);
    while(r--){
      int a,b,c,d;
      cin>>a>>b>>c>>d;
      b--;
      if(!d){
	tem[b].m++;
	tem[b].tm+=a+mistake[b][c]*20;
      }
      else
	mistake[b][c]++;
    }
    sort(tem,tem+t);
    for(int i=0;i+1<t;++i){
      cout<<tem[i].id;
      if(tem[i].m==tem[i+1].m && tem[i].tm==tem[i+1].tm) cout << "=";
      else cout << ",";
    }
    cout << tem[t-1].id << endl;
  }
  return 0;
}