### constant

PNLTY = 20

### subroutines

def cmp_t(a, b)
  ($rights[a] != $rights[b]) ?
    $rights[b] <=> $rights[a] : $times[a] <=> $times[b]
end

def cmp_t_s(a, b)
  ct = cmp_t(a, b)
  (ct != 0) ? ct : b <=> a
end

### main

loop do
  m, tn, pn, rn = gets.split.map(&:to_i)
  break if (m | tn | pn | rn) == 0

  $rights = tn.times.map{0}
  $times = tn.times.map{0}
  ngs = tn.times.map{pn.times.map{0}}
  
  rn.times do
    mi, ti, pi, ji = gets.split.map(&:to_i)
    ti -= 1
    pi -= 1

    if ji == 0
      $rights[ti] += 1
      $times[ti] += ngs[ti][pi] * PNLTY + mi
    else
      ngs[ti][pi] += 1
    end
  end
  #p [$rights, $times]

  ts = (0...tn).sort{|a, b| cmp_t_s(a, b)}

  print (ts[0] + 1)
  for i in (1...tn)
    print (cmp_t(ts[i - 1], ts[i]) != 0 ? ',' : '=')
    print (ts[i] + 1)
  end
  puts
end