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

typedef struct{
    int nodeID;
    int childNum;
    int *child;
    int parent;
}Node;

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

void selectionSort(int,Node[]);

int main(int argc, char** argv) {
    int size, childNum, id;
    scanf("%d\n", &size);
    Node tree[size];
    for(int i = 0; i < size; i++){
        scanf("%d %d", &id, &childNum);
        initNode(&tree[i],id,childNum);
        for(int j = 0; j < childNum; j++)
            scanf("%d", &tree[i].child[j]);
    }
    selectionSort(size,tree);        
    printTree(size, tree);
    return (EXIT_SUCCESS);
}

void initNode(Node *n, int id, int num){
    int *temp = (int*)malloc(num * sizeof(int));
    n->nodeID = id;
    n->childNum = num;
    n->child = temp;
}

int getParent(int size, Node tree[size], Node target, int numOfInit){
    for(int i = 0; i < numOfInit; i++)
        for(int j = 0; j < tree[i].childNum; j++)
            if(target.nodeID == tree[i].child[j])
                return tree[i].nodeID;
    return -1;
}

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

int getDepth(int size, Node tree[size], Node target){
    int count = 0;
    int parent = getParent(size,tree,target,size);
    if(parent >= 0){
        count += getDepth(size,tree,tree[parent]);
        count++;
    }
    return count;
}

int getNodeType(int size, Node tree[size], Node target){    //Return types: -1 = Root
    if(target.parent == -1)
        return -1;
    else{
        if(target.childNum == 0)
            return 1;
        return 0;
    }
}

void selectionSort(int size, Node array[size]){
    int minLoc;
    Node temp;
    for(int i = 0; i < size; i++){
        minLoc = i;
        for(int j = i; j < size; j++)
            if(array[j].nodeID < array[minLoc].nodeID)
                minLoc = j;
        temp = array[i];
        array[i] = array[minLoc];
        array[minLoc] = temp;
    }
}

