{-# LANGUAGE BangPatterns #-}

import           Control.Applicative
import           Control.Monad
import qualified Data.ByteString.Char8 as B

import           Data.Array.IArray
import           Data.Array.IO
import           Data.Array.MArray
import           Text.Printf

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

format :: String
format = "node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s\n"

getSib :: Int -> Array Int Int -> Array Int [Int] -> Int
getSib n pary cary
    | p == -1   = -1
    | otherwise = head $ filter (/= n) cs
  where
    p  = pary ! n
    cs = cary ! p

getDegree :: Int -> Array Int [Int] -> Int
getDegree n cary = length $ filter (/= -1) (cary ! n)

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

getHeight :: Int -> Array Int [Int] -> Int
getHeight n cary
    | n == -1            = 0
    | l == -1 && r == -1 = 0
    | otherwise          = 1 + max (getHeight l cary) (getHeight r cary)
  where
    [l, r] = cary ! n

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
            when (c /= -1) $ writeArray paryM c i

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

    forM_ [0 .. n - 1] $ \i -> do
        let p = pary ! i
        let cs = filter (/= -1) (cary ! i)
        let typ = case () of
                _ | p == -1 -> "root"
                  | null cs -> "leaf"
                  | otherwise -> "internal node"

        printf format
            i
            p
            (getSib i pary cary)
            (getDegree i cary)
            (getDepth i pary)
            (getHeight i cary)
            typ

