solve :: [Int] -> Int -> Int ->	String
solve all@(x:xs) n count
  | count > n =	[]
  | x == count = '1' : ' ' : solve xs n (count + 1)
  | otherwise = '0' : ' ' : solve all n (count + 1)

ctr :: Int -> [[Int]] -> [String]
ctr n (x:xs)
  | null xs = []
  | otherwise = solve (x ++ [-1]) n 1 : ctr n xs

main = do
  n <- readLn
  getContents >>= mapM_ putStrLn . map init . ctr n . (++[[1]]) . map (map read . drop 2 . words) . lines