import Data.Char
import Data.List

ans :: Int -> [[Int]]
ans 0 = [[]]
ans 1 = [[1]]
ans n =
  let is = reverse $ [1..n]
      i = map (\i -> map (i:) (ans (n-i)) ) is
      j = concat i
      k = filter (\x -> x == (reverse $  sort x)) j
  in
    k

to_str :: [Int] -> String
to_str [] = []
to_str (x:[]) = [intToDigit x]
to_str (x:xs) =
  (intToDigit x):(' ':(to_str xs))

main = do
  l <- getContents
  let n  = map read $ lines l :: [Int]
      n' = takeWhile (/=0) n
      o  = map (\x -> map to_str $ ans x) n'
  mapM_ (mapM_ putStrLn) o