var nodeList = Array<Treee?>(100000) { null }

fun main(args: Array<String>) {

    val nodeCount = readLine()!!.toLong()

    for (i in 1..nodeCount) {

        var inputs = readLine()!!.split(" ")
        val left = inputs[1].toInt()
        val right = inputs[2].toInt()
        val id = inputs[0].toInt()

        // 自身を作る
        if (nodeList[id] == null) {
            nodeList[id] = Treee(id, -1)
        }

        // 子供を記録
        if (left != -1) {
            val childLeftNode = nodeList[left] ?: Treee(left)
            childLeftNode.parent = id
            nodeList[left] = childLeftNode

            nodeList[id]!!.left = left
        }

        if (right != -1) {
            val childRightNode = nodeList[right] ?: Treee(right)
            childRightNode.parent = id
            nodeList[right] = childRightNode

            nodeList[id]!!.right = right
        }
    }

    var rootNode = nodeList.filter {
        it?.parent == -1
    }[0]

    setDepth(rootNode!!.id, 0)

    getHeight(rootNode.id)

    nodeList.filterNotNull().forEach { it.print() }
}

fun setDepth(currentIndex: Int, currentDepth: Int) {
    // 左から巡回

    if (nodeList[currentIndex]!!.left != -1) {
        setDepth(nodeList[currentIndex]!!.left, currentDepth + 1)
    }

    // 保存
    nodeList[currentIndex]!!.depth = currentDepth

    if (nodeList[currentIndex]!!.right != -1) {
        setDepth(nodeList[currentIndex]!!.right, currentDepth + 1)
    }
}

fun getHeight(currentIndex: Int): Int {


    // 左から巡回
    val heights = arrayListOf<Int>()

    // 左右なければ高さ0にするので
    heights.add(0)
    if (nodeList[currentIndex]!!.left != -1) {
        heights.add(getHeight(nodeList[currentIndex]!!.left) + 1)
    }

    if (nodeList[currentIndex]!!.right != -1) {
        heights.add(getHeight(nodeList[currentIndex]!!.right) + 1)
    }

    // 保存
    nodeList[currentIndex]!!.height = heights.max()!!
    return heights.max()!!
}

class Treee(
    var id: Int,
    var parent: Int = -1,
    var left: Int = -1,
    var right: Int = -1,
    var depth: Int? = null,
    var height: Int? = null
) {

    fun print() {
        println("node $id: parent = $parent, sibling = ${getSibling()}, degree = ${getDegree()}, depth = $depth, height = $height, ${type()}")
    }

    fun type(): String {
        if (parent == -1) {
            return "root"
        }

        if (left == -1 && right == -1) {
            return "leaf"
        }

        return "internal node"
    }

    fun getSibling(): Int {
        if (parent == -1) {
            return -1
        }
        if (nodeList[parent]!!.right != id) {
            return nodeList[parent]!!.right
        }
        if (nodeList[parent]!!.left != id) {
            return nodeList[parent]!!.left
        }
        return -1
    }

    fun getDegree(): Int {
        var count = 0
        if (right != -1) {
            count++
        }
        if (left != -1) {
            count++
        }

        return count
    }
}
