import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;
import std.bigint;
import std.container;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

const real eps = 1e-10;

void main(){
	while(true) {
		auto mtpr = readInts();
		auto m = mtpr[0];
		auto t = mtpr[1];
		auto p = mtpr[2];
		auto r = mtpr[3];
		if((m|t|p|r) == 0) return;

		auto cp = new int[](t);
		auto pe = new int[](t);
		auto w = new int[][](t,p);
		for(int i; i < r; ++i) {
			auto mtpj = readInts();
			auto mi = mtpj[0];
			auto ti = mtpj[1]-1;
			auto pi = mtpj[2]-1;
			auto ji = mtpj[3];
			if(ji == 0) {
				++cp[ti];
				pe[ti] += mi + w[ti][pi] * 20;
			} else {
				++w[ti][pi];
			}
		}
		auto te = iota(1, t+1).array;
		bool win(Tuple!(int, int, int) a, Tuple!(int, int, int) b) {
			return a[0] > b[0] || (a[0] == b[0] && a[1] < b[1]);
		}
		zip(cp, pe, te).sort!((a, b) => win(a,b) || (!win(a,b) && !win(b, a) && a[2] > b[2]));
		write(te[0]);
		for(int i = 1; i < t; ++i) {
			if(win(tuple(cp[i-1], pe[i-1], 0), tuple(cp[i], pe[i], 0))) {
				write(",");
			} else {
				write("=");
			}
			write(te[i]);
		}
		writeln();
	}
}