main :: IO ()
main = do
  [_,w] <- fmap read . words <$> getLine :: IO [Int]
  _ <- readLn :: IO Int
  ls <- fmap read . words <$> getLine :: IO [Int]
  putStrLn . sprint $ solve ls w

solve :: [Int] -> Int -> [[Int]]
solve ls w = plist $ zip [1..] (part ls' w) where
  ls' = concat $ zipWith (flip replicate) [1..]  ls
  plist = fmap (\(h,b) -> if even h then reverse b else b)

part :: [Int] -> Int -> [[Int]]
part ls w = take w ls : part (drop w ls) w

sprint :: [[Int]] -> String
sprint mat = unlines $ fmap (unwords . fmap show) mat
