main :: IO ()
main = do
    [_, w] <- map read . words <$> getLine :: IO [Int]
    n <- read <$> getLine :: IO Int
    as <- zip [1..] . map read . words <$> getLine :: IO [(Int, Int)]
    let ns = concatMap (\(c, n) -> replicate n c) as :: [Int]
    let ms = map (\(i, x) -> if even i then reverse x else x) 
           . zip [1..] $ f w ns
    mapM_ (putStrLn . unwords . map show) ms

f _ [] = []
f w ns = take w ns : f w (drop w ns)