#include<iostream>
#include<algorithm>
using namespace std;

struct data{
  int ac,pe,id;
  bool operator == (const data& p) const{
    return ac==p.ac && pe==p.pe;
  }
  bool operator < (const data& p) const{
    if(ac!=p.ac)return ac>p.ac;
    if(pe!=p.pe)return pe<p.pe;
    return id>p.id;
  }
};

int wa_cnt[51][11];

data team[51];

void init();

int main(){
  int M,T,P,R;
  while(1){
    cin>>M>>T>>P>>R;
    if(M==0&&T==0&&P==0&&R==0)break;
    init();
    for(int i=0;i<R;i++){
      int m,t,p,j;
      cin>>m>>t>>p>>j;t--;
      if(m>M)continue;
      if(j==0){
	team[t].ac++;
	team[t].pe+=(wa_cnt[t][p]*20);	
	team[t].pe+=m;
      }else{
	wa_cnt[t][p]++;
      }
    }

    sort(team,team+T);
    for(int i=0;i<T;i++){
      if(i>0){
	if(team[i-1]==team[i])cout<<'=';
	else cout<<',';
      }
      cout<<team[i].id;
    }
    cout<<endl;
  }
  return 0;
}

void init(){
  for(int i=0;i<51;i++)for(int j=0;j<11;j++)wa_cnt[i][j]=0;
  for(int i=0;i<51;i++){
    team[i].id=i+1;
    team[i].pe=team[i].ac=0;
  }
}