main = do
    [_, w] <- fmap (map read . words) getLine :: IO [Int]
    _ <- fmap (map read . words) getLine :: IO [Int]
    xs <- fmap (map read . words) getLine :: IO [Int]
    -- print $ unwords $ head $solve w xs
    mapM_ putStrLn $ map unwords $ solve w xs

solve :: Int -> [Int] -> [[String]]
solve n = f (id, reverse) . m
  where
    f _ [] = []
    f op xs = ((fst op) (take n xs)) : (f (swap op) (drop n xs))
    swap (a, b) = (b, a)
m :: [Int] -> [String]
m = concatMap (\(c, n) -> replicate n (c : [])) . zip ['1' ..]
