using System;
using System.Collections.Generic;

namespace ConsoleApplication1
{

    struct Node
    {
        public int depth;
        public int height;
        public int p;
        public int sonnum;
        public string type;       
    }


    class Program
    {

        static int v;  //深さのカウント
        static int[] sib;  //自分の兄弟を求める
        static int h;
        static int maxh;
        static int u;
        static int root;

        static void Depth(int k, Node[] a)
        {
            if (a[k].p == -1)
            {
                return;
            }
            else
            {
                k = a[k].p;
                v++;
                Depth(k, a);
                return;
            }

        }

        //Heightを求める
        static void Height(Node[] a, int num)
        {
            maxh = 0;          
            foreach(var s in leaflist)
            {
                h = 0;
                u = s;
                while (true)
                {

                    if (u == num)
                    {
                        break;
                    }
                    if (u == root)
                    {
                        h = 0;
                        break;
                    }                                 
                    h++;
                    u = a[u].p;
                }

                if(maxh < h)
                {
                    maxh = h;
                }
                
            }

        }

        //nodeの種類typeを割り当てる
        static void Type(int n, Node[] a)
        {
            for (int i = 0; i < n; i++)
            {               
                if (a[i].p == -1)
                {
                    a[i].type = "root";
                    root = i;
                }
                else if (a[i].sonnum == 0)
                {
                    a[i].type = "leaf";
                    leaflist.Add(i);
                }
                else
                {
                    a[i].type = "internal node";
                }
            }
            return;
        }

        static int id;
        static int l;
        static int r;
        static string[] input;
        static List<int> leaflist;
        static int n;
            
        static void Main(string[] args)
        {
            n = int.Parse(Console.ReadLine());

            Node[] a = new Node[n];
            sib = new int[n];
            leaflist = new List<int>();

            for(int i = 0; i < n; i++)
            {
                a[i].p = -1;                
                a[i].depth = 0;
                sib[i] = -1;
            }
         
            
            for (int i = 0; i < n; i++)
            {
                input = Console.ReadLine().Split(' ');
                id = int.Parse(input[0]);
                l = int.Parse(input[1]);
                r = int.Parse(input[2]);

                //siblingを求める
                if (l != -1)
                {
                    sib[l] = r;
                    
                    a[l].p = id;                    
                }
                if (r != -1)
                {                  
                    sib[r] = l;
                  
                    a[r].p = id;
                }

                //子供の数
                if (l == -1 && r == -1)
                {
                    a[id].sonnum = 0;
                }
                else if (l != -1 && r != -1)
                {
                    a[id].sonnum = 2;
                }
                else
                {
                    a[id].sonnum = 1;
                }


            }

            //Typeを求める
            Type(n, a);


                             
            //Heightを求める
            for(int i = 0; i < n; i++)
            {
                Height(a, i);
                a[i].height = maxh;
            }



            //Depthを求める
            for (int i = 0; i < n; i++)
            {
                v = 0;
                Depth(i, a);
                a[i].depth = v;
            }



            for (int i = 0; i < n; i++)
            {
                Console.WriteLine($"node {i}: parent = {a[i].p}, sibling = {sib[i]}, degree = {a[i].sonnum}, depth = {a[i].depth}, height = {a[i].height}, {a[i].type}");
            }

        }
    }
}



Measured memory_bytes: 16024