using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

class Node
{
    internal int parent;
    internal int depth;
    internal string type;
    internal int left, right;
    internal int degree;
    internal int sibling;
    internal int height;
    internal List<int> children;
    public Node() {
        parent = -1;
        depth = 0;
        type = "";
        left = -1;
        right = -1;
        sibling = -1;
        height = 0;
        children = new List<int>();
    }
}

class B
{
    public static void Main() {
        int n = int.Parse(Console.ReadLine());
        Node[] nodes = new Node[n];
        for(int i = 0; i < n; i++) {
            nodes[i] = new Node();
        }
        for(int i = 0; i < n; i++) {
            int[] data = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            if (data[1] != -1 && data[2] != -1) {
                nodes[data[0]].left = data[1];
                nodes[data[0]].right = data[2];
                nodes[data[1]].parent = data[0];
                nodes[data[2]].parent = data[0];
                nodes[data[0]].degree = 2;
                nodes[data[1]].sibling = data[2];
                nodes[data[2]].sibling = data[1];
            } else if (data[1] != -1) {
                nodes[data[0]].left = data[1];
                nodes[data[1]].parent = data[0];
                nodes[data[0]].degree = 1;
            } else if (data[2] != -1) {
                nodes[data[0]].right = data[2];
                nodes[data[2]].parent = data[0];
                nodes[data[0]].degree = 1;
            }
        }
        for(int i = 0; i < n; i++) {
            nodes[i].depth = depthSet(nodes, i);
            nodes[i].height = heightSet(nodes, i);
            if (nodes[i].parent != -1) {
                nodes[i].type = (nodes[i].left!=-1||nodes[i].right!=-1) ? "internal node" : "leaf";
            } else {
                nodes[i].type = "root";
            }
        }
        StringBuilder output = new StringBuilder();
        for(int i=0;i<n;i++) {
            output.AppendLine("node " + i + ": parent = " + nodes[i].parent +
                    ", sibling = " + nodes[i].sibling + ", degree = " + nodes[i].degree +
                    ", depth = " + nodes[i].depth + ", height = " + nodes[i].height +
                    ", " + nodes[i].type);
        }
        Console.Write(output);
    }
    static int depthSet(Node[] nodes, int id) {
        int d = 0;
        if (nodes[id].parent != -1) {
            d=1+depthSet(nodes, nodes[id].parent);
            return d;
        } else {
            return 0;
        }
    }
    static int heightSet(Node[] nodes, int id) {
        int rh, lh;
        rh = lh = 0;
        if(nodes[id].left!=-1&&nodes[id].right!=-1){
            lh = 1 + heightSet(nodes, nodes[id].left);
            rh = 1 + heightSet(nodes, nodes[id].right);
        } else if (nodes[id].left != -1) {
            lh = 1 + heightSet(nodes, nodes[id].left);
        }else if (nodes[id].right != -1) {
            rh = 1 + heightSet(nodes, nodes[id].right);
        } else {
            return 0;
        }
        return Math.Max(rh, lh);
    }
}


Measured memory_bytes: 9244