#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define pb push_back
typedef pair<int,int> P;
typedef pair<P,int> Q;
#define fi first
#define sc second
int num[105],len[105];
int cnt[105][105];
int m,t,p,r;

int main(){
	while(1){
		cin>>m>>t>>p>>r;
		if(m == 0) return 0;
		rep(i,105)rep(j,105){
			num[i] = len[i] = cnt[i][j] = 0;
		}
		rep(i,r){
			int a,b,c,d; cin>>a>>b>>c>>d; b--;
			if(d != 0){
				cnt[b][c]++;
			}
			else{
				num[b]++;
				len[b] += a+cnt[b][c]*20;
			}
		}
		vector<Q>vec;
		rep(i,t) vec.push_back(Q(P(num[i],-len[i]),i));
		sort(vec.begin(),vec.end(),greater<Q>());
		for(int i=0;i<vec.size();i++){
			cout << vec[i].sc+1 ;
			if(i != vec.size()-1){
				if(vec[i].fi == vec[i+1].fi) cout << "=" ;
				else cout << "," ;
			}
		}
		cout << endl;
	}
}

