main = do
  [h,w]<-map read.words<$>getLine
  getLine
  as<-map read.words<$>getLine
  putStr.unlines.map (unwords.map show) $ solve h w as

solve h w as = formAns $ colorSeq as 1
  where
  formAns [] = []
  formAns xs = line1 : reverse line2 : formAns remainings
    where
    (line1,l2rem) = splitAt w xs
    (line2,remainings) = splitAt w l2rem
  colorSeq [] _ = []
  colorSeq (a:as) c = replicate a c ++ colorSeq as (c+1)
