{-# LANGUAGE BangPatterns #-}

import           Control.Applicative
import           Control.Monad
import qualified Data.ByteString.Char8 as B
import qualified Data.IntMap.Strict    as M
import           Data.Sequence         ((<|), (><), (|>))
import qualified Data.Sequence         as S

import           Data.Array.IArray
import           Data.Array.MArray
import           Data.Array.IO

readi :: B.ByteString -> Int
readi bs | Just (n, _) <- B.readInt bs = n

calcDepth :: Int -> Array Int Int -> Int
calcDepth n pary = go 0 n
  where
    go !d !m
        | p == -1   = d
        | otherwise = go (d+1) p
      where
        p = pary ! m

printList :: [Int] -> IO ()
printList [] = putStr "[]"
printList (x:xs) = putStr ("[" ++ show x) >> go xs >> putStr "]"
  where
    go []     = return ()
    go (y:ys) = putStr (", " ++ show y) >> go ys

main :: IO ()
main = do
    n <- readLn :: IO Int
    let f (i:_:cs) = (i, cs)
    xss <- fmap (f . fmap readi . B.words) . B.lines <$> B.getContents
    -- xss :: [(Int, [Int])]

    paryM <- newArray (0, n-1) (-1) :: IO (IOArray Int Int)
    forM_ xss $ \(i, cs) -> do
        forM_ cs $ \c -> do
            writeArray paryM c i

    pary <- freeze paryM :: IO (Array Int Int)
    let cary = array (0, n-1) xss :: Array Int [Int]

    forM_ [0 .. n-1] $ \i -> do
        let parent = pary ! i
        let children = cary ! i
        putStr $ "node " ++ show i ++ ": "
        putStr $ "parent = " ++ (show parent) ++ ", "
        putStr $ "depth = " ++ (show $ calcDepth i pary) ++ ", "
        let ntype = case () of
                _ | parent == -1  -> "root"
                  | null children -> "leaf"
                  | otherwise     -> "internal node"
        putStr $ ntype ++ ", "
        printList children
        putStrLn ""

