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

class Program
{

    public void Proc()
    {
        int nodeCount = int.Parse(Console.ReadLine());
        Dictionary<int, TreeNd> dic = new Dictionary<int, TreeNd>();
        List<TreeNd> list = new List<TreeNd>();
        for (int i = 0; i < nodeCount; i++)
        {
            string[] inpt = Console.ReadLine().Split(' ');
            int id = int.Parse(inpt[0]);
            int itemCount = int.Parse(inpt[1]);

            TreeNd newItem;
            if (dic.ContainsKey(id))
            {
                newItem = dic[id];
            }
            else
            {
                newItem = new TreeNd(id);
                dic.Add(id, newItem);
                list.Add(newItem);
            }
            for(int j=0; j<itemCount; j++) {
                int subId = int.Parse(inpt[2 + j]);
                TreeNd subNd;
                if (dic.ContainsKey(subId))
                {
                    subNd = dic[subId];
                }
                else
                {
                    subNd = new TreeNd(subId);
                    dic.Add(subId, subNd);
                    list.Add(subNd);
                }
                subNd.Parent = newItem;
                newItem.SubTree.Add(subNd);
            }
        }
        list.Sort((a, b) => {
            int dir = 1;
            if (a.NodeId == b.NodeId)
            {
                return 0;
            }
            else if (a.NodeId < b.NodeId)
            {
                return dir * -1;
            }
            else
            {
                return dir;
            }
        });
        foreach (TreeNd item in list)
        {
            Console.WriteLine(item.ToString());
        }
    }

    public class TreeNd
    {
        public int NodeId = -1;
        public TreeNd Parent = null;
        public List<TreeNd> SubTree = new List<TreeNd>();

        public TreeNd(int id)
        {
            this.NodeId = id;
        }
        public string GetNodeType()
        {
            if (this.Parent == null)
            {
                return "root";
            }
            else if (SubTree.Count <= 0)
            {
                return "leaf";
            }
            else
            {
                return "internal node";
            }
        }

        private Nullable<int> DepthValue = null;
        public int Depth
        {
            get
            {
                if (this.DepthValue != null)
                {
                    return this.DepthValue.Value;
                }
                if (this.Parent == null)
                {
                    this.DepthValue = 0;
                }
                else
                {
                    this.DepthValue = this.Parent.Depth + 1;
                }
                return this.DepthValue.Value;
            }
        }
        public override string ToString()
        {
            //node 0: parent = -1, depth = 0, root, [1, 4, 10]
            //node 1: parent = 0, depth = 1, internal node, [2, 3]
            //node 2: parent = 1, depth = 2, leaf, []
            StringBuilder subitems = new StringBuilder();
            subitems.Append("[");
            for (int i = 0; i < this.SubTree.Count; i++)
            {
                if (i > 0)
                {
                    subitems.Append(", ");
                }
                subitems.Append(this.SubTree[i].NodeId);
            }
            subitems.Append("]");
            string ret = "node " + this.NodeId + ": parent = " + ((this.Parent == null) ? -1 : this.Parent.NodeId) + ", depth = " + this.Depth + ", " + this.GetNodeType() + ", " + subitems.ToString();
            return ret;
        }
    }

    static void Main(string[] args)
    {
        Program prg = new Program();
        prg.Proc();
    }
}

Measured memory_bytes: 38876