#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define MAX 1000000
/*--------構造定義---------*/
typedef struct node{
 int id;
 int depth;
 char name[20];/*root or leaf*/
 int childnum;/*子の番号を文字列で*/
 int pareid;
 struct node *point; 
}node;
/*---------------------------*/

/*--------構造定義---------*/
typedef struct CHILD{
 int childid;
 struct CHILD *point; 
}CHILD;
/*---------------------------*/

CHILD* makecell(int x){
CHILD *new=malloc(sizeof(CHILD));

new->childid=x;
new->point=NULL;

return new;
}




/*---------------depthを求める---------------*/
int depthcheck(node node[],int i){

 if(node[i].pareid==-1)return 0;
 else{return depthcheck(node,node[i].pareid)+1;}

}
/*------------------------------------------------------------*/


int main(){
int i,j,n,d,x;
int root,count;
int depthmax=-1;
int depthmin=21;
node node[MAX];
char temp[15];
int t;
int c;
CHILD S[MAX];
CHILD **p;
CHILD *q;
CHILD *r;

scanf("%d",&n);/*node数の読み込み*/



/*-------------ノードの初期化-------------*/
for(i=0;i<n;i++){
node[i].id=i;
node[i].point=NULL;
node[i].depth=0;
node[i].childnum=0;
node[i].pareid=-1;
}
/*--------------------------------------*/

/*-------------ノードの初期化-------------*/
for(i=0;i<n;i++){
 S[i].childid=-1;
 S[i].point=NULL; 
}
/*--------------------------------------*/



/*---------nodeの読み込み---------------------*/
for(i=0;i<n;i++){
scanf("%d",&t);
node[t].id=t;
scanf("%d",&node[t].childnum);

if(node[t].childnum!=0){
  for(j=0;j<node[t].childnum;j++){
   scanf("%d",&x);
   node[x].point=&node[t];
   node[x].pareid=t;
   
   if(S[t].childid==-1){
    S[t].childid=x;
   }else{
     p=&(S[t].point);
     while((*p)!=NULL){p=&((*p)->point);}
     (*p)=makecell(x);
   }

  }/*for end*/

  }
else if(node[t].childnum==0){strncpy(node[t].name,"leaf",4);node[t].name[4]='\0';}
}
/*---------------------------------------*/





/*----------root探索---------------*/

/*--------------------------------*/



/*-----------------depthの計測-----------------------*/
for(i=0;i<n;i++){
count=0;
node[i].depth=depthcheck(node,i);

/*--------------------------------------------------*/}




/*----------------nodeの種類の決定--------------------------*/
for(i=0;i<n;i++){
if(node[i].depth==0){strncpy(node[i].name,"root",4);node[i].name[4]='\0';}
else if(node[i].name[0]!='l'){strncpy(node[i].name,"internal node",13);node[i].name[13]='\0';}
}
/*------------------------------------------------------------*/


/*表示*/
for(i=0;i<n;i++){c=1;

printf("node %d: parent = %d, depth = %d, %s, [",i,node[i].pareid,node[i].depth,node[i].name);

if(node[i].childnum==0){printf("]\n");}/*leaf*/

else if(node[i].childnum==1){/*子が1つ*/
 printf("%d]\n",S[i].childid);
}else{/*子が2以上*/
 printf("%d, ",S[i].childid);
 q=S[i].point;
 while(q->point!=NULL){
  printf("%d, ",q->childid);
  q=q->point;
 }
  printf("%d]\n",q->childid);
 }





}



return 0;
}



/*時間切れ*/
