// #ifdef DEBUG
// #define _GLIBCXX_DEBUG
// #endif
#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>

// these require C++11
#include <unordered_set>
#include <unordered_map>
#include <random>
#include <thread>
#include <chrono>

using namespace std;

#define int long long

#define all(c) c.begin(), c.end()
#define repeat(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x) 
#endif

template<typename A,typename B>
ostream &operator<<(ostream&os,const pair<A,B>& p){
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

typedef complex<double> point;

// template<typename T,std::size_t N>
// struct _v_traits {using type = std::vector<typename _v_traits<T,N-1>::type>;};
// template<typename T>
// struct _v_traits<T,1> {using type = std::vector<T>;};
// template<typename T,std::size_t N=1>
// using vec = typename _v_traits<T,N>::type;

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

struct Team{
    int id;
    vector<int> time;
    vector<int> try_count;
    vector<char> ok;
};

int succeeded(const Team& t){
    int ret = 0;
    for(int i : t.time){
        ret += (0 < i);
    }
    return ret;
}

int get_time(const Team& t){
    int ret = 0;
    for(int i=0;i<t.time.size();i++){
        if(t.time[i] > 0){
            ret += (t.time[i]-1) + 20 * t.try_count[i];
        }
    }
    return ret;
}

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

    while(true){
        int M,T,P,R;
        cin >> M >> T >> P >> R;
        if(M == 0 and T == 0 and P == 0 and R == 0) break;

        vector<Team> teams;
        for(int i=0;i<T;i++){
            teams.push_back(Team{i+1,vector<int>(P,0),vector<int>(P,0)});
        }
        for(int i=0;i<R;i++){
            int m,t,p,j;
            cin >> m >> t >> p >> j;
            t--;p--;
            if(j == 0){
                teams[t].time[p] = m+1;
            }else{
                teams[t].try_count[p]++;
            }
        }

        sort(teams.begin(),teams.end(),[](const Team& left,const Team& right){
                if(succeeded(left) != succeeded(right)){
                    return succeeded(left) > succeeded(right);
                }
                if(get_time(left) != get_time(right)){
                    return get_time(left) < get_time(right);
                }
                return left.id > right.id;
            });

        for(int i=0;i<T;i++){
            if(i > 0){
                if(([](const Team& left,const Team& right){
                            return succeeded(left) == succeeded(right) and 
                                get_time(left) == get_time(right);

                        })(teams[i-1],teams[i])){
                    cout << "=";
                }else{
                    cout << ",";
                }
            }
            cout << teams[i].id;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1232