#include <stdio.h>

#define MAX_NO_OF_NODES 100000

typedef enum{
    root,
    internal_node,
    leaf
} node_state;

typedef struct{
    int parent;
    int left;
    int right;
} node_t;

void matchParent(int, int);
int getDepth(int);
void printNode(int);

int n;
node_t node[MAX_NO_OF_NODES];

int main()
{
    int i, j, id, degree, tempChild, currentChild;
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) node[i].parent = node[i].left = node[i].right = -1;
    
    for (i = 0; i < n; i++){
        scanf("%d %d", &id, &degree);
        if (degree != 0){
            for (j = 0; j < degree; j++) {
                scanf("%d", &tempChild);
                if (j == 0) node[id].left = tempChild;
                else node[currentChild].right = tempChild;
                node[tempChild].parent = id;
                currentChild = tempChild;
            }
        }
    }
    
    for (i = 0; i < n; i++){
        printNode(i);
    }
    
}

int getDepth(int targetID){
    int i = 0;
    while (node[targetID].parent != -1){
        i++;
        targetID = node[targetID].parent;
    }
    return i;
}

void printNode(int i){
    int j;
    int depth = getDepth(i);
    printf("node %d: parent = %d, ", i, node[i].parent);
    printf("depth = %d,", depth);
    
    if (node[i].parent == -1) printf(" root, [");
    else if (node[i].left == -1) printf(" leaf, [");
    else printf(" internal node, [");

    if (node[i].left != -1){
        printf("%d", node[i].left);
        int cur = node[i].left;
        while(node[cur].right != -1){
            printf(", %d", node[cur].right);
            cur = node[cur].right;
        }
    }
    printf("]\n");
}


