/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/* 
 * File:   main.c
 * Author: Mu-Chan
 *
 * Created on July 9, 2018, 6:18 PM
 */

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

typedef struct Node Node;

struct Node{
    int id;
    Node* parent;
    Node* sibling;
    Node* child;
};

typedef struct{
    Node *array;
}Tree;

void initNode(Node*);
void printTree(int,Node[]);
int getDepth(Node*);

int main(int argc, char** argv) {
    int size;
    scanf("%d\n", &size);
//    Tree tree;
    Node array[size];
    int loc, childNum, tempParent;
    int tempChild = -1;
    
    for(int i = 0; i < size; i++)
        initNode(&array[i]);
    
    for(int i = 0; i < size; i++){
        scanf("%d %d", &tempParent, &childNum);
        array[tempParent].id = tempParent;
        for(int j = 0; j < childNum; j++){
            scanf("%d", &loc);
            array[loc].parent = array+tempParent;
            if(j == 0)
                array[tempParent].child = array+loc;
            if(tempChild >= 0)
                array[tempChild].sibling = array+loc;
            tempChild = loc;
        }
        tempChild = -1;
    }
//    tree.array = array;
    printTree(size,array);
    
    return (EXIT_SUCCESS);
}

void initNode(Node *n){
    n->id = -1;
    n->child = NULL;
    n->sibling = NULL;
    n->parent = NULL;
}

void printTree(int size, Node tree[size]){
    int parent;
    char type[15];
    int temp;
    for(int i = 0; i < size; i++){
        printf("node %d: ", i);
        if(tree[i].parent == NULL)
            parent = -1;
        else
            parent = tree[i].parent->id;
        printf("parent = %d, ", parent);
        printf("depth = %d, ", getDepth(&tree[i]));
        if(tree[i].parent == NULL)
            strcpy(type,"root");
        else{
            if(tree[i].child != NULL)
                strcpy(type,"internal node");
            else
                strcpy(type,"leaf");
        }
        printf("%s, [", type);
        if(tree[i].child != NULL){
            temp = tree[i].child->id;
            printf("%d", temp);
            while(tree[temp].sibling != NULL){
                if(tree[temp].sibling != NULL)
                    printf(", ");
                temp = tree[temp].sibling->id;
                printf("%d", temp);
            }
        }
        printf("]\n");
    }
}

int getDepth(Node* target){
    int count = 0;
    if(target->parent != NULL){
        count++;
        count += getDepth(target->parent);
    }
    return count;
}

