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

namespace ConsoleApplication1
{
    class Node
    {
        internal int parent, left, right;
        internal int sibling, degree;
        internal int depth, height;
        internal string type;

        public Node()
        {
            parent = -1;
            left = -1;
            right = -1;
            sibling = -1;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            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[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

                if (input[1] != -1 && input[2] != -1)
                {
                    nodes[input[0]].left = input[1];
                    nodes[input[1]].parent = input[0];
                    nodes[input[1]].sibling = input[2];
                    nodes[input[0]].right = input[2];
                    nodes[input[2]].parent = input[0];
                    nodes[input[2]].sibling = input[1];
                    nodes[input[0]].degree = 2;
                }
                else if (input[1] != -1)
                {
                    nodes[input[0]].left = input[1];
                    nodes[input[1]].parent = input[0];
                    nodes[input[0]].degree++;
                }
                else if (input[2] != -1)
                {
                    nodes[input[0]].right = input[2];
                    nodes[input[2]].parent = input[0];
                    nodes[input[0]].degree++;
                }
            }

            Stack<Node> stkDepth = new Stack<Node>();
            Stack<Node> stkHeight = new Stack<Node>();

            for (int i = 0; i < n; i++)
            {
                if (nodes[i].parent == -1)
                {
                    nodes[i].type = "root";
                    stkDepth.Push(nodes[i]);
                }
                else
                {
                    if (nodes[i].left >= 0 || nodes[i].right >= 0)
                    {
                        nodes[i].type = "internal node";
                    }
                    else
                    {
                        nodes[i].type = "leaf";
                        stkHeight.Push(nodes[i]);
                    }
                }
            }

            while (stkDepth.Count > 0)
            {
                Node temp = stkDepth.Pop();

                if (temp.left >= 0)
                {
                    nodes[temp.left].depth = temp.depth + 1;
                    stkDepth.Push(nodes[temp.left]);
                }

                if (temp.right >= 0)
                {
                    nodes[temp.right].depth = temp.depth + 1;
                    stkDepth.Push(nodes[temp.right]);
                }
            }

            while (stkHeight.Count > 0)
            {
                Node temp = stkHeight.Pop();

                if (temp.parent != -1)
                {
                    if (nodes[temp.parent].height < temp.height + 1)
                        nodes[temp.parent].height = temp.height + 1;
                    stkHeight.Push(nodes[temp.parent]);
                }
            }

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < n; i++)
            {
                sb.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(sb);
        }
    }
}

Measured memory_bytes: 10168