module Main where
main = interact $ printer . solver . parser
int = read :: String -> Int

printer = unlines . map (unwords . map show)
parser = map int . words

solver (h:w:n:cs) = v3
  where
    v1 = concat $ map (uncurry  replicate) $ zip cs [1..]
    v2 = map (take w) $ take h $ iterate (drop w) v1
    v3 = zipWith ($) (concat $ repeat [id , reverse]) v2
