#include<bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
typedef pair<int,int> P;

//-----------------------------------------------------------------------

pair<P,int> t[55];
int wrong[55][15];

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a,b,c,d;
    while(cin>>a>>b>>c>>d,a)
    {
	REP(i,b) t[i]=make_pair(P(0,0),-i-1);
	REP(i,b) REP(j,c) wrong[i][j]=0;

	REP(i,d){
	    int e,f,g,h;
	    cin>>e>>f>>g>>h;
	    f--,g--;
	    if(h==0){
		t[f].first.first--;
		t[f].first.second+=e+20*wrong[f][g];
	    }else{
		wrong[f][g]++;
	    }
	}
	sort(t,t+b);
	cout<<-t[0].second;
	for(int i=1;i<b;i++){
	    if(t[i-1].first.first==t[i].first.first &&
	       t[i-1].first.second==t[i].first.second){
		cout<<"=";
	    } else cout<<",";
	    cout<<-t[i].second;
	}
	cout<<endl;
    }
}
