module Main where

import Debug.Trace
import Data.List
import qualified Data.Sequence as S
import qualified Data.ByteString.Char8 as B
import Data.Int
import Data.Char
import Data.Array
import Data.Maybe
import qualified Data.Map as M
import Data.Ord
import Data.Functor
import Control.Applicative
import Control.Monad
import Text.Printf

solve :: Int -> [[Int]] -> [(Int, Int, Int, String, [Int])]
solve n l = sort (iter 0 (-1) root) where
    iter depth parent node = info:(concatMap (iter (depth+1) node) (children!node)) where
        info :: (Int, Int, Int, String, [Int])
        info = (node, parent, depth,
                case node of
                 _  | node == root      -> "root"
                    | null (children!node)  -> "leaf"
                    | otherwise         -> "internal node",
                    children!node)

    root = iter 0 where
        iter x 
            | tree!x == -1 = x
            | otherwise = iter (tree!x)

    (tree, children) = iter [] [] (sort l) where
        iter ac cc [] = ((listArray (0, n-1) (replicate n (-1))) // ac,
                         (listArray (0, n-1) (replicate n [])) // cc)
        iter ac cc ((x:0:ls):ns) = iter ac cc ns 
        iter ac cc ((x:y:ls):ns) = iter ([(i, x) | i <- ls]++ac) ((x, ls):cc) ns 

readIntLn:: IO Int
readIntLn = (fst . fromJust . B.readInt) <$> B.getLine

readIntList:: IO [Int]
readIntList = map (fst . fromJust . B.readInt) . B.words <$> B.getLine

print' (n, p, d, t, l) = do 
    putStr $ "node "++show n++": parent = "++show p++", depth = "++show d++", "++t++", "
    printInts l

printInts l = do
    putStr "["
    iter l where
        iter [] = putStrLn "]"
        iter [x] = putStrLn $ show x++"]"
        iter (x:xs) = do
            putStr $ show x++", "
            iter xs 

main :: IO() 
main = do
    n <- readIntLn
    l <- replicateM n readIntList
    mapM_ print' $ solve n l 

