using System;
using System.Text;

namespace ALDS1_7_A
{
    public struct node
    {
        public int parent;
        public int left;
        public int right;

        public node(int parent, int left, int right)
        {
            this.parent = parent;
            this.left = left;
            this.right = right;
        }
    }

    class Program
    {
        public static int nil = -1;

        static int getdepth(int u, node[] T)
        {
            int d = 0;
            while (T[u].parent != nil)
            {
                u = T[u].parent;
                d++;
            }
            return d;
        }

        static int[] D = new int[100000];

        static void setdepth(int u, int p,node[] T)
        {
            D[u] = p;
            if (T[u].right != nil)
            {
                setdepth(T[u].right, p,T);
            }
            if (T[u].left != nil)
            {
                setdepth(T[u].left, p + 1,T);
            }
        }
        
        static StringBuilder sbchildren(int u,node[] T)
        {
            var sb = new StringBuilder();
            sb.Append(" [");
            int c = T[u].left;

            while (c !=nil)
            {
                sb.Append(c+", ");
                c = T[c].right;
            }

            sb.Remove(sb.Length-2, 2);

            return sb;
        }

        static int rootchecker(node[] T)
        {
            for (int i = 0; i < T.Length; i++)
            {
                if (T[i].parent == nil)
                {
                    return i;
                }
            }
            return 0;
        }
 
        static void Main(string[] args)
        {
            int n = getint();

            node[] T = new node[n];
            for (int i = 0; i < n; i++)
            {
                T[i].parent = nil;
                T[i].left = nil;
                T[i].right = nil;
            }
            
            for (int i = 0; i < n; i++)
            {
                var input = getsplit();
                int[] a = Array.ConvertAll(input, int.Parse);
                if (a[1] >= 1)
                {
                    T[a[0]].left = a[2];
                    int j;
                    for (j = 2; j <= a[1]; j++)
                    {
                        T[a[j]].right = a[j + 1];
                        T[a[j]].parent = a[0];
                    }
                   
                    T[a[j]].parent = a[0];
                }
              
            }

            int r = rootchecker(T);

            setdepth(r, 0, T);

            for (int i = 0; i < n; i++)
            {
                var sb = new StringBuilder();
                sb.Append("node " + i + ": ");
                sb.Append("parent = " + T[i].parent + ", ");
                sb.Append("depth = " + D[i] + ", ");

                if (D[i] == 0)
                {
                    sb.Append("root,");
                    if (sbchildren(i,T).Length != 0)
                    {
                        sb.Append(sbchildren(i, T));
                    }
                    else
                    {
                        sb.Append(" [");
                    }
                    sb.Append("]");
                }
                else
                {
                    
                    if (sbchildren(i,T).Length == 0)
                    {
                        sb.Append("leaf, []");
                    }
                    else
                    {
                        sb.Append("internal node,");
                        sb.Append(sbchildren(i, T));
                        sb.Append("]");
                    }
                }
                Console.WriteLine(sb);
            }          
        }

        public static string[] getsplit()
        {
            string[] x = Console.ReadLine().Split(' ');
            return x;
        }
        public static int getint()
        {
            int x = int.Parse(Console.ReadLine());
            return x;
        }
    }
}

Measured memory_bytes: 22904