/*<stdio.h>
  #include<stdlib.h>
  int main(){
  int n, i, j, k, pcount = 0, flag = 0;
  int *array_number, *array_children, **array_node, *array_nodes;
  int *array_parent;

  scanf("%d", &n);
  array_number = malloc(sizeof(int) * n);
  array_children = malloc(sizeof(int) * n);
  array_nodes = malloc(sizeof(int) * (n - 1));
  array_node = malloc(sizeof(int *) * n);
  array_parent = malloc(sizeof(int) * n);


  for(i = 0; i < n; i++){
  scanf("%d", &array_number[i]);
  scanf("%d", &array_children[i]);
  array_node[i] = malloc(sizeof(int) * array_children[i]);
  for(j = 0; j < array_children[i]; j++){
  scanf("%d", &array_node[i][j]);
  array_nodes[pcount] = array_node[i][j];
  pcount++;
  }
  }
  
  for(i = 0; i < n; i++){
  for(j = 0; j < array_children[i]; j++){
  printf("%d ", array_node[i][j]);
  }
  if(array_children[i] != 0)   printf("\n");
  }

  for(i = 0; i < n; i++){//rootsearch
  for(j = 0; j < n - 1; j++){
  array_parent[i] = -1;
  if(array_number[i] == array_nodes[j]){
  array_parent[i] = 0;
  break;
  }
  }
  }
  
  printf("--------------------------------------------------\n");
  for(i = 0; i < n; i++)
  for(j = 0; j < array_children[i]; j++)
  if(array_number[i] == array_node[i][j])
  array_parent[i] = 100;

  printf("--------------------------------------------------\n");

  for(i = 0; i < n; i++)
  printf("%d ", array_parent[i]);
  printf("\n");

  for(i = 0; i < n; i++){
  printf("%d ", array_number[i]);
  }
  printf("\n");

  printf("--------------------------------------------------\n");

  for(i = 0; i < n; i++){
  printf("node %d: ", array_number[i]);
  printf("parent = %d, ", array_parent[i]);
  printf("depth = ?, ");
  if(array_children[i] == 0){
  printf("leaf, []\n");
  }else{
  printf("internal node, [");
  for(j = 0; j < array_children[i] - 1; j++)
  printf("%d, ", array_node[i][j]);
  printf("%d]\n", array_node[i][j]);
  }
  }

  return 0;
  }
*/

#include<stdio.h>

typedef struct{
  int p;
  int l;
  int r;
}Node; 

Node T[100001];
int n, D[10001];

void print(int u){

  int i, c;

  printf("node %d: ", u);
  printf("parent = %d,", T[u].p);
  printf("depth = %d,", D[u]);

  if(T[u].p == -1)    printf("root, ");
  else if(T[u].l == -1)    printf("leaf, ");
  else    printf("internal code, ");
  
  printf("[");
  
  for(i = 0, c = T[u].l; c != -1; i++, c = T[c].r){
    if(i)      printf(", ");
    printf("%d", c);
  }
  printf("]\n");
}
      
int rec(int u, int p){
  D[u] = p;

  if(T[u].r != -1)    rec(T[u].r, p);
  if(T[u].l != -1)    rec(T[u].l, p + 1);
}

int main(){
  int i,j, d, v, c, l, r;
  scanf("%d", &n);

  for(i = 0; i < n; i++)
    T[i].p = T[i].l = T[i].r = -1;
  
  for(i = 0; i < n; i++){
    scanf("%d%d", &v,&d);
    for(j = 0; j < d; j++){
      scanf("%d", &c);
      if(j == 0)   T[v].l = c;
      else	   T[l].r = c;
      l = c;
      T[c].p = v;
    }
  }
  for(i = 0; i < n; i++){
    if(T[i].p == -1)   r = i;
  }
  
  rec(r, 0);

  for(i = 0; i < n; i++)    print(i);

  return 0;
}