#include<stdio.h>
#include<stdlib.h>
#define M 100000
 struct node{
  int id;
  int* k;
   int n;
  int p;
  int d;
  int type;
  struct node* next;
  struct node* prev; 
};
typedef struct node * NodePointer ;

NodePointer nil;

NodePointer t[M];
int m[M];
void depth(int key){
  NodePointer x;
  int i=0;
  for(x = t[key];x!=nil;x=x->prev,i++){
 
  }
  t[key]->d=i;
  if(i==0)t[key]->type=-1;
}



void init(){
  nil=malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil; 
}



void def(int key,int n){
  NodePointer x;
  int * m;
  x=t[key];
  x = malloc(sizeof(struct node));
  x->id = key; 
  x->prev = nil; 
  x->n=n;
  x->k=malloc(sizeof(int)*n+1);
  if(n==0)x->type=1;
  else x->type=0;
}



void printList(int n){
  int i,j; 
  for(i=0;i<n;i++){
    depth(i);
    printf("node %d: parent = %d, depth = %d, ",i,t[i]->p,t[i]->d);
    if( t[i]->type== -1) printf("root, ");
    else if(t[i]->type == 0)printf("internal node, ");
    else printf("leaf, ");
    if(t[i]->n==0)printf("[]\n");
    else {
      printf("[");
      for(j=0;j<t[i]->n -1;j++){
    printf("%d, ",t[i]->k[j]);
      }
      printf("%d]\n",t[i]->k[j]);
    }
  }
 

}




void chine(int a,int b,int j){

  t[b]->prev=t[a];
  t[a]->k[j]=b;

}





int main(){
  int i,j,a,b,e,n;


  scanf("%d",&n);
  init();

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


    scanf("%d %d",&a,&b);
    def(a,b);

  }

    for(j=0;j<b;j++){


       scanf("%d",&e);
       chine(i,e,j);


    }
    
/*   } */
/*   printList(n); */
  

  


  return 0;
}