import Data.List
import Data.Maybe

data Record = Record Int Int Int deriving Eq

instance Ord Record where
 (<=) (Record tid1 pid1 pena1) (Record tid2 pid2 pena2)
  = pid1 > pid2 || (pid1 == pid2 && pena1 < pena2) || (pid1 == pid2 && pena1 == pena2 && tid1 < tid2)

instance Show Record where
 show (Record tid pid pena) = show tid ++ " " ++ show pid ++ " " ++ show pena

main = interact $ unlines . map (init . unlines . map show . record . judge) . read' . lines
 where
  read' ("0 0 0":_) = []
  read' (tpr:xs) = (t,p,logs) : read' xs'
   where
    [t,p,r] = map read (words tpr)
    (logs',xs') = splitAt r xs
    logs = map ((\[tid,pid,time,stat] -> (read tid, read pid, read time, stat)) . words) logs'
  record = sort . map (\(t,pr,pe,ws) -> Record t pr pe) 

judge (t,p,logs) = foldl' total initr logs
 where
  initr = [(tid,0,0,replicate p 0) | tid<-[1..t]]
  total acc (tid,pid,time,stat)
   | stat == "CORRECT" = let (t,pr,pe,ws) = query tid acc in (t,pr+1,pe+time+(ws!!(pid-1)*1200),ws) : (filter ((/=tid).fst') acc)
   | stat == "WRONG" = let (t,pr,pe,ws) = query tid acc in (t,pr,pe,wrong pid ws) : (filter ((/=tid).fst') acc)
   where
    wrong pid = map (\(i,n) -> if i==pid then n+1 else n) . zip [1..]
    query i = fromJust . find ((==i) . fst')
  fst' (x,_,_,_) = x