#include<stdio.h>
#define MAX 25

typedef struct{
  int id;
  int left;
  int right;
  int sibling;
  int parent;
  int degree;
  int depth;
  int height;
  char *type;
}Tree;

int getParent(int);
void getSibling(int);
int getDegree(int);
void getDepth(int);
void getHeight(int);

Tree A[MAX];
int n,k;

int main()
{
  int i,count,p,s,d,j;
  Tree tmp;
  scanf("%d",&n);
  for(i = 0;i < n;i++){
    scanf("%d%d%d",&A[i].id,&A[i].left,&A[i].right);
  }

  for(i = 0;i < n;i++){
    if(A[i].id != i) {
      for(j = 0;j < n;j++){
	if(i == A[j].id){
	  tmp = A[i];
	  A[i] = A[j];
	  A[j] = tmp;
	}
      }
    }
  }

  for(i = 0;i < n;i++){
    p = getParent(i);
    getSibling(i);
    d = getDegree(i);
    if(p == 0) A[i].type = "root";
    else if(d == 0) A[i].type = "leaf";
    else A[i].type = "internal node";
    getDepth(i);
  }

  for(i = n-1;i >= 0;i--){
    getHeight(i);
  }

  for(i = 0;i < n;i++){
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s\n",A[i].id,A[i].parent,A[i].sibling,A[i].degree,A[i].depth,A[i].height,A[i].type);
  }
  return 0;
}

int getParent(int x)
{
  int i,count;
  for(i = 0;i < n;i++){
    if(A[x].id == A[i].left || A[x].id == A[i].right){
      A[x].parent = A[i].id;
      count = 1;
      break;
    }
  }
  if(count == 0) A[x].parent = -1;
  return count;
}

void getSibling(int x)
{
  int i,count;
  for(i = 0;i < n;i++){
    if(A[x].id == A[i].right){
      A[x].sibling = A[i].left;
      count = 1;
    }
    else if(A[x].id == A[i].left){
      A[x].sibling = A[i].right;
      count = 1;
    }
  }
  if(count == 0){
    A[x].sibling = -1;
  }
}

int getDegree(int x)
{
  A[x].degree = 2;
  if(A[x].left == -1){
    A[x].degree -= 1;
  }
  
  if(A[x].right == -1){
    A[x].degree -= 1;
  }
  return A[x].degree;
}

void getDepth(int x)
{
  int i;
  if(A[x].parent == -1) {
    A[x].depth = 0;
  }
  for(i = 0;i < n;i++){
    if(A[x].id == A[i].right || A[x].id == A[i].left){
      A[x].depth = A[i].depth + 1;
    }
  }
}

void getHeight(int x)
{
  int h1=0,h2=0,i;
  if(A[x].degree == 0) A[x].height = 0;
  for(i = n-1;i >= 0;i--){
    if(A[x].left == A[i].id) h1 = A[i].height + 1;
    else if(A[x].right == A[i].id) h2 = A[i].height + 1;
  }
  if(h1 >= h2) A[x].height = h1;
  else if(h2 > h1)A[x].height = h2;
}