#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <time.h>
#include <string.h>

typedef struct{
    int other;
    int parent;
    int depth;
    char *type;
    int* c;
    bool done_f;
}Node;

void input(Node*,int);
void allprint(Node*,int);
void depthjud(Node*,int);

const char* root="root";
const char* internal="internal node";
const char* leaf="leaf";

int main(){
    Node* np;
    int n;

    scanf("%d",&n);
    np=malloc(sizeof(Node)*n);
    for(int i=0;i<n;i++){
        (np+i)->parent=-1;
    }
    input(np,n);
    depthjud(np,n);
    allprint(np,n);

    return 0;
}

void input(Node* np,int max){
    int node_num;
    int other;
    int buff;

    for(int i=0;i<max;i++){
        scanf("%d%d",&node_num,&other);
        //scanf("%d",&other);
        (np+node_num)->other=other;
        (np+node_num)->c=malloc(sizeof(int)*other);
        for(int j=0;j<other;j++){
            scanf("%d",&buff);
            (np+buff)->parent=node_num;
            (np+node_num)->c[j]=buff;
        }
    }
    for(int i=0;i<max;i++){
        if((np+i)->parent==-1){
            (np+i)->type=root;
            (np+i)->done_f=true;
            continue;
        }
        if((np+i)->other==0){
            (np+i)->type=leaf;
            continue;
        }
        (np+i)->type=internal;
    }
}

void allprint(Node* np,int max){
    Node* np_for_print;
    for(int i=0;i<max;i++){
        np_for_print=np+i;
        //printf("other %d\n",np_for_print->other);
        printf("node %d: parent = %d, depth = %d, %s, [",i,np_for_print->parent,np_for_print->depth,np_for_print->type);
        for(int j=0;j<np_for_print->other;j++){
            if(j!=np_for_print->other-1)
                printf("%d, ",np_for_print->c[j]);
            else{
                printf("%d",np_for_print->c[j]);
            }
        }
        printf("]\n");
    }
}

void depthjud(Node* np,int max){
    //printf("in depthjud root node_num %d parent %d\n",np[0].node_num,np[0].parent);
    for(int i=0;i<max;i++){
        //printf("in depthjud i %d node_num %d parent %d\n",i,(np+i)->node_num,(np+i)->parent);
        if(strcmp((np+i)->type,"root")==0){
            continue;
        }
        if(!(np+(np+i)->parent)->done_f){
            continue;
        }
        if((np+i)->other==0){
            (np+i)->depth=(np+(np+i)->parent)->depth+1;
            (np+i)->done_f=true;
        }
        else{
            (np+i)->depth=(np+(np+i)->parent)->depth+1;
            (np+i)->done_f=true;
        }
    }
    for(int i=0;i<max;i++){
        //printf("in depthjud i %d node_num %d parent %d depth %d\n",i,(np+i)->node_num,(np+i)->parent,(np+i)->depth);
        if((np+i)->type==root){
            continue;
        }
        if((np+i)->done_f){
            continue;
        }
        if((np+i)->other==0){
            (np+i)->depth=(np+(np+i)->parent)->depth+1;
        }
        else{
            (np+i)->depth=(np+(np+i)->parent)->depth+1;
        }
    }
    
    //printf("in depthjud root node_num %d parent %d\n",np[0].node_num,np[0].parent);
}
