using System;
using System.Linq;

namespace ALDS1_7_A_RootedTrees
{
	class Program
	{
		static void Main ( string[] args )
		{
			int dataCount = int.Parse (Console.ReadLine ());
			Tree tree = new Tree (dataCount);

			for (int lp = 0; lp < dataCount; lp++)
			{
				int[] inputNum = Console.ReadLine ().Split (' ').Select (int.Parse).ToArray ();
				int nodeID = inputNum[0];
				int nodeCount = inputNum[1];

				int left = 0;
				for (int lp2 = 0; lp2 < nodeCount; lp2++)
				{
					int c = inputNum[2 + lp2];

					if (lp2 == 0)
					{
						int leftNode = c;
						tree.SetLeft (nodeID, leftNode);
					}
					else
					{
						int rightNode = c;
						tree.SetRight (left, rightNode);
					}

					left = c;
					tree.SetParent (c, nodeID);
				}
			}

			int root = tree.GetParent ();

			tree.GetDepth (root, 0);

			for (int lp = 0; lp < dataCount; lp++)
			{
				tree.PrintNode (lp);
			}

		}
	}

	class Node
	{
		public int Parent { set; get; }
		public int Left { set; get; }
		public int Right { set; get; }
	}

	class Tree
	{
		public Tree ( int capacity )
		{
			this.NodeArray = new Node[capacity];
			for (int lp = 0; lp < NodeArray.Length; lp++)
			{
				this.NodeArray[lp] = new Node ();
				NodeArray[lp].Parent = NodeArray[lp].Left = NodeArray[lp].Right = Null;
			}

			this.DepthArray = new int[capacity];
		}

		private Node[] NodeArray { set; get; }
		private int[] DepthArray { set; get; }
		private const int Null = -1;

		public void SetLeft ( int nodeNumber, int leftNumber )
		{
			NodeArray[nodeNumber].Left = leftNumber;
		}
		public void SetRight ( int nodeNumber, int rightNumber )
		{
			NodeArray[nodeNumber].Right = rightNumber;
		}
		public void SetParent ( int nodeNumber, int parentNumber )
		{
			NodeArray[nodeNumber].Parent = parentNumber;
		}

		public int GetParent ()
		{
			int index = 0;

			while (NodeArray[index].Parent != Null)
			{
				index++;
			}
			return index;
		}

		public int GetDepth ( int nodeNumber )
		{
			int count = 0;

			while (NodeArray[nodeNumber].Parent != Null)
			{
				nodeNumber = NodeArray[nodeNumber].Parent;
				count++;
			}

			return count;
		}

		//???????????¨????????????????????±???????±???????
		public int[] GetDepth ( int nodeNumber, int depth )
		{
			DepthArray[nodeNumber] = depth;

			if (NodeArray[nodeNumber].Right != Null)
			{
				GetDepth (NodeArray[nodeNumber].Right, depth);
			}
			if (NodeArray[nodeNumber].Left != Null)
			{
				GetDepth (NodeArray[nodeNumber].Left, depth + 1);
			}

			return DepthArray;
		}

		public void PrintNode ( int nodeNumber )
		{
			Console.Write ("node " + nodeNumber + ": ");
			Console.Write ("parent = " + NodeArray[nodeNumber].Parent + ", ");
			Console.Write ("depth = " + DepthArray[nodeNumber] + ", ");

			if (NodeArray[nodeNumber].Parent == Null)
			{
				Console.Write ("root, ");
			}
			else if (NodeArray[nodeNumber].Left == Null)
			{
				Console.Write ("leaf, ");
			}
			else
			{
				Console.Write ("internal node, ");
			}

			Console.Write ("[");

			for (int lp = 0, node = NodeArray[nodeNumber].Left; node != Null; lp++, node = NodeArray[node].Right)
			{
				if (lp != 0)
					Console.Write (", ");

				Console.Write (node);
			}

			Console.WriteLine ("]");
		}
	}
}

Measured memory_bytes: 26144