#include<stdio.h>
#define MAX 100000

int confirm_depth(int);

struct Node// This variable is used only confirm the node is root,internal,or leaf.
{
  int parent , left , right;
};

/*
struct insert //This variable is used to remember how many children the node has.
{
  int id,number_of_children;
};
*/

//struct insert in[100000];
struct Node node[MAX] = {-1,-1,-1};

int main()
{
  
  int n,k,i,j,id,child_id,next,count=0;
  scanf("%d",&n);
  for(i = 0 ; i<n ;i++)
    {
      node[i].parent = -1;
      node[i].left = -1;
      node[i].right = -1;
      //printf("node[0]={%d,%d,%d}\n",node[0].parent,node[0].left,node[0].right);
    }
     
  for(i = 0 ;i < n ; i++ )
    {
      //scanf("%d %d",&in[i].id,&in[i].number_of_children);
      scanf("%d %d",&id,&k);
      //for(j =count ; j < count+ in[i].number_of_children ; j++)
      //printf("TEST node[%d].left = %d\n",i,node[i].left);
      for(j =count ; j < count+k ; j++)
	{

	  next = child_id;
	  scanf("%d",&child_id);
	  
	  //if(j>count)node[id].right = child_id;
	  //printf("node[%d].right = %d\n",id,node[id].right);
	  if(j == count)
	    {
	      node[id].left = child_id;
	      //printf("j = %d\n",j);
	      //printf("id = %d\n",id);
	      //printf("node[%d].left = %d\n",id,node[id].left);
	    }
	  
	  if(j>count )
	    {
	      if(j == count +1)
		{
		  
		  node[node[id].left].right = child_id;
		  
		  //printf("\nnode[%d].right = %d\n\n",id,node[id].right);
		}
	      else node[next].right = child_id;
	      //printf("child_id = %d\n",child_id);
	      //printf("node[%d].right = %d\n",next,node[next].right);
	    }
	  //node[child_id].parent  = in[i].id;
	  node[child_id].parent  = id;
	  
	  
	    
	}
      count = count + k;
      //  printf("count = %d\n",count);
      
    }

  //printf("TEST node[%d].left = %d\n",6,node[6].left);



  
  //printf("\n\n");
  for(i = 0; i <n ; i++)
    {
      //printf("TEST node[%d].left = %d\n",i,node[i].left);
      printf("node %d: parent = %d, depth = %d, ",i,node[i].parent,confirm_depth(i));
      if(node[i].parent == -1) printf("root, ");
      else if(node[i].left != -1) printf("internal node, ");
      else printf("leaf, ");

      printf("[");
      if(node[i].left >= 0)
	{

	  next = node[i].left;
	  //printf("  node[%d].left = %d\n",i,node[i].left);
	  //printf("[");
	   if(node[i].left >= 0)printf("%d",node[i].left);
	  
	  while(node[next].right >=0)
	    {
	      
	      printf(", %d",node[next].right);
	      next = node[next].right;
	    }
	  
	 
	}
      printf("]");
      printf("\n");
    }

}
  

int confirm_depth(int id)
{
  int i,depth = 0;
  while(node[id].parent != -1 )
    {
      id = node[id].parent;
      depth++;
    }
  return depth;
}
  
  /*
  printf("\n\n");
  //printf("%d\n",NULL);
  for(i = 0; i <n ; i++)
    {
      printf("node %d:parent = %d property = %d \n ",i,node[i].parent,node[i].right);
      printf("node[%d].left = %d\n",i,node[i].left);
      
      if(node[i].left >= 0)
	{
	  printf("test\n");
	  next = node[i].left;
	  printf("node[%d].left = %d\n",i,node[i].left);
	  
	  while(next >=0)
	    {
	     
	      printf("right = %d\n",node[next].right);
	      printf("next = %d\n ",next);
	      next = node[next].right;
	      printf("next[next.right] = %d\n ",next);
	      break;
	      
	    }
	  printf("\n");
	}
    }

}
  */



Measured memory_bytes: 2948