using System;
using System.Linq;
using System.Text;

namespace ALDS1_7_B_BinaryTrees
{
	class Program
	{
		static void Main ( string[] args )
		{
			//input
			int dataCount = int.Parse (Console.ReadLine ());
			BinaryTree binaryTree = new BinaryTree (dataCount);

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

				binaryTree.NodeArray[nodeNumber].Left = left;
				binaryTree.NodeArray[nodeNumber].Right = right;

				if (left != BinaryTree.Null)
					binaryTree.NodeArray[left].Parent = nodeNumber;
				if (right != BinaryTree.Null)
					binaryTree.NodeArray[right].Parent = nodeNumber;
			}

			int root = 0;

			for (int lp = 0; lp < dataCount; lp++)
			{
				if (binaryTree.NodeArray[lp].Parent == BinaryTree.Null)
				{
					root = lp;
					break;
				}
			}

			//process
			binaryTree.SetDepth (root, 0);
			binaryTree.SetHeight (root);

			//output
			for (int lp = 0; lp < dataCount; lp++)
			{
				binaryTree.PrintNode (lp);
			}
		}
	}
}

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

class BinaryTree
{
	public BinaryTree ( int capacity )
	{
		this.NodeArray = new Node[capacity];

		for (int lp = 0; lp < NodeArray.Length; lp++)
		{
			this.NodeArray[lp] = new Node ();
			this.NodeArray[lp].Parent = Null;
		}

		this.HeightArray = new int[capacity];
		this.DepthArray = new int[capacity];
	}

	public Node[] NodeArray { private set; get; }
	public int[] HeightArray { private set; get; }
	public int[] DepthArray { private set; get; }

	public const int Null = -1;

	//????????????????????????
	public int GetSibling ( int nodeNumber )
	{
		//?????????????????£??????
		if (NodeArray[nodeNumber].Parent == Null)
		{
			return Null;
		}

		int parentIndex = NodeArray[nodeNumber].Parent;

		//???????????????????´???§?????????????´?????????¨??????????????°
		bool isRight = NodeArray[parentIndex].Left != nodeNumber;
		bool isExistLeft = NodeArray[parentIndex].Left != Null;

		if (isRight && isExistLeft)
		{
			//??????????´??????????
			return NodeArray[parentIndex].Left;
		}

		//???????????????????´???§?????????????´?????????¨??????????????°
		bool isLeft = NodeArray[parentIndex].Right != nodeNumber;
		bool isExistRight = NodeArray[parentIndex].Right != Null;

		if (isLeft && isExistRight)
		{
			//??????????´??????????
			return NodeArray[parentIndex].Right;
		}

		//????????\???
		return Null;
	}
	//????????°?????????
	public int GetDegree ( int nodeNumber )
	{
		int count = 0;
		if (NodeArray[nodeNumber].Left != Null)
			count++;
		if (NodeArray[nodeNumber].Right != Null)
			count++;
		return count;
	}
	//??????????????±????????????
	public void SetDepth ( int nodeNumber, int depth )
	{
		//???????????????????????¨???????????´???
		if (nodeNumber == Null)
		{
			return;
		}

		//???????????±??????????´???????
		DepthArray[nodeNumber] = depth;

		//??±???????¶???????????????????????????±???????±???????
		SetDepth (NodeArray[nodeNumber].Left, depth + 1);

		//??±???????¶???????????????????????????±???????±???????
		SetDepth (NodeArray[nodeNumber].Right, depth + 1);
	}
	//??????????????????????????????
	public int SetHeight ( int nodeNumber )
	{
		int height = 0;
		int height2 = 0;

		//???????????¨??????????????°
		if (NodeArray[nodeNumber].Left != Null)
		{
			//?????°??§?????????????????????????´?+1????????°???????´???????
			height = SetHeight (NodeArray[nodeNumber].Left) + 1;
		}
		//???????????¨??????????????°
		if (NodeArray[nodeNumber].Right != Null)
		{
			//?????°??§?????????????????????????´?+1????????°???????´???????
			height2 = SetHeight (NodeArray[nodeNumber].Right) + 1;
		}

		//?????¨????????§????????????????????¨????????????
		return HeightArray[nodeNumber] = Math.Max (height, height2);
	}
	//?±???§?????????
	public string GetType ( int nodeNumber )
	{
		if (NodeArray[nodeNumber].Parent == Null)
			return "root";
		if (NodeArray[nodeNumber].Left == Null && NodeArray[nodeNumber].Right == Null)
			return "leaf";
		else
			return "internal node";
	}

	public void PrintNode ( int nodeNumber )
	{
		StringBuilder output = new StringBuilder (150);

		output.Append ("node " + nodeNumber + ": ");
		output.Append ("parent = " + NodeArray[nodeNumber].Parent + ", ");
		output.Append ("sibling = " + GetSibling (nodeNumber) + ", ");
		output.Append ("degree = " + GetDegree (nodeNumber) + ", ");
		output.Append ("depth = " + DepthArray[nodeNumber] + ", ");
		output.Append ("height = " + HeightArray[nodeNumber] + ", ");
		output.Append (GetType (nodeNumber));

		Console.WriteLine (output);
	}
}

Measured memory_bytes: 9644