main = do
  [h, w] <- map read . words <$> getLine
  n <- readLn
  as <- map read . words <$> getLine
  f w (g as) 0
 
g [] = []
g (a:as) = (take a . repeat $ show a) ++ g as
 
f w cs p
  | cs == [] = putStr ""
  | p == 0 = putStrLn as >> f w bs 1
  | p == 1 = (putStrLn $ reverse as) >> f w bs 0
    where (as, bs) = splitAt w cs
 