#include <stdio.h>
#include <stdlib.h>

struct {
  int id;
  int left;
  int right;
  int parent;
  int sibling;
  int degree;
  int depth;
  int height;
  int flag;
} typedef Tree;

int main(){
  Tree *t;
  int n, id, left, right, p, depth_leftmax, depth_rightmax, i, j;

  scanf("%d", &n);
  t = (Tree *)malloc(sizeof(Tree) * n);
  if(t == NULL){
    printf("error!\n");
    exit(-1);
  }
  for(i = 0; i < n; i++){
    scanf("%d %d %d", &id, &left, &right);
    t[id].id = id;
    t[id].left = left;
    t[id].right = right;
    t[id].parent = -1;
    t[id].sibling = -1;
    t[id].degree = 0;
    t[id].depth = 0;
    t[id].height = 0;
    t[id].flag = 0;
  }

  for(i = 0; i < n; i++){
    if(t[i].left != -1){
      t[i].degree = 2;

      t[ t[i].left ].parent = t[i].id;
      t[ t[i].left ].sibling = t[i].right;
      t[ t[i].left ].depth += 1;

      t[ t[i].right ].parent = t[i].id;
      t[ t[i].right ].sibling = t[i].left;
      t[ t[i].right ].depth += 1;

      p = t[i].parent;
      while(p != -1){
	t[ t[i].left ].depth += 1;
	t[ t[i].right ].depth += 1;
	p = t[p].parent;
      } 
    }
  }
 
  left = t[0].left;
  right = t[0].right;
  depth_leftmax = 0;
  depth_rightmax = 0;
  for(i = 0; i< n; i++){
    p = t[i].parent;
     while(p != -1){
       if(p == left || t[i].id == left){
	 if(depth_leftmax < t[i].depth) depth_leftmax = t[i].depth;
	 t[i].flag = 1;
       }
       if(p == right || t[i].id == right){
	 if(depth_rightmax < t[i].depth) depth_rightmax = t[i].depth;
	 t[i].flag = 2;
      }
       p = t[p].parent;
     }
  }

  for(i = 0; i < n; i++){
    if(t[i].flag == 0){
      if(depth_leftmax >= depth_rightmax) t[i].height = depth_leftmax;
      else t[i].height = depth_rightmax;
	}
    if(t[i].flag == 1) t[i].height = depth_leftmax - t[i].depth;
    if(t[i].flag == 2) t[i].height = depth_rightmax - t[i].depth;
    if(t[i].degree == 0) t[i].height = 0;
  }

  for(i = 0; i < n; i++){
    printf("node %d: parent = %d, sibling = %d ", t[i].id, t[i].parent, t[i].sibling);
    printf("degree = %d, depth = %d, height = %d, ", t[i].degree, t[i].depth, t[i].height);
    if(t[i].parent == -1) printf("root\n");
    else if(t[i].degree != 0) printf("internal node\n");
    else printf("leaf\n");
  }

  free(t);
  
  return 0;
}