import Data.List.Split
import Data.Maybe
import qualified Data.ByteString.Char8 as B
main=mapM_(putStr.solve).chunksOf 3.map(map(fst.fromJust.B.readInt).B.words).B.lines=<<B.getContents
solve[[h,w],[n],as]=unlines.map(unwords.map show)$zipWith($)(cycle[id,reverse])$chunksOf w$concat$zipWith replicate as [1..n]