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

#define UND_NODE -1

typedef struct {
//    int id;
    int firstChild;
    int nextSibling;
    int parent;
} BinaryNode;

//int nodeIndexFromId(BinaryNode nodes[], int length, int id) {
//    for (int i = 0; i < length; i++)
//        if(nodes[i].id == id)
//            return i;
//}

int nodeDepthFromId(BinaryNode nodes[], int length, int id) {
    int i = 0;
    while (nodes[id].parent != UND_NODE) {
        i++;
        id = nodes[id].parent;
    }
    return i;
}

void printArray(int array[], int length) {
    for (int i = 0; i < length; i++) {
        if (i) printf(", ");
        printf("%d", array[i]);
    }
}


int main(int argc, char** argv) {
    int nNodes, nChildren;
    scanf("%d", &nNodes);
    
    BinaryNode nodes[nNodes]; // Binary tree
    int i, j, parentNodeId, currentNodeId, incomingNodeId;
    
    for (i = 0; i < nNodes; i++)
        nodes[i].parent = nodes[i].firstChild = nodes[i].nextSibling = UND_NODE;
    
    for (i = 0; i < nNodes; i++) {
        scanf("%d", &(parentNodeId)); // id
        scanf("%d", &(nChildren)); // k, number of children

        for (j = 0; j < nChildren; j++) {
            scanf("%d", &(incomingNodeId));
            if (j == 0) 
                nodes[parentNodeId].firstChild = incomingNodeId;
            else 
                nodes[currentNodeId].nextSibling = incomingNodeId;
            
            currentNodeId = incomingNodeId;
            
            nodes[incomingNodeId].parent = parentNodeId;
            
//            printf("parentNodeId: %d: incomingNodeId: %d\n", parentNodeId, incomingNodeId);
//            printf("incoming;   node %d: parent = %d\n", incomingNodeId, nodes[incomingNodeId].parent);
//            printf("parentNode; node %d: parent = %d\n", parentNodeId, nodes[parentNodeId].parent);
        }
    }
    
    for (i = 0; i < nNodes; i++) {
        j = nodeDepthFromId(nodes, nNodes, i);
        
        printf("node %d: parent = %d, depth = %d, ", i, nodes[i].parent, j);
        
        // node types
        if (nodes[i].parent == UND_NODE)
            printf("root, ");
        else if (nodes[i].firstChild > 0)
            printf("internal node, ");
        else 
            printf("leaf, ");
        
        // children
        printf("[");
        j = i;
        if (nodes[j].firstChild != UND_NODE) {
            printf("%d", nodes[j].firstChild);
            while (nodes[j].nextSibling != UND_NODE) {
                printf(", %d", j = nodes[j].nextSibling);
            }
        }
        printf("]\n");
    }
    

    return (EXIT_SUCCESS);
}


