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

#define NOT_FOUND -1
#define SENTINEL 100001


typedef struct Node_ {
    int id; // id of current node
    int nChildren; // number of children
    int * children; // id of children are stored here
    struct Node_ * parentPointer; // parent pointers are stored here
    int depth;
} Node;

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

void swap(Node Array[], int i, int j) {
    Node temp;
    temp = Array[i];
    Array[i] = Array[j];
    Array[j] = temp;
}

int partition(Node Array[], int pIndex, int rIndex) {
    Node x = Array[rIndex];
    int i = pIndex;
    
    for (int j = pIndex; j < rIndex; j++)
        if (Array[j].id <= x.id)
            swap(Array, i++, j);

    swap(Array, i, rIndex);
    return i;
}

void quickSort(Node Array[], int pIndex, int rIndex) {
    if (pIndex < rIndex) {
        int qIndex = partition(Array, pIndex, rIndex);
        quickSort(Array, pIndex, qIndex - 1);
        quickSort(Array, qIndex + 1, rIndex);
    }
}



void merge(Node array[], int left, int mid, int right) {
    int nL = mid - left;
    int nR = right - mid;
    
    Node Left[nL + 1], Right[nR + 1];
    int i, j, k;
    
    for (i = 0; i < nL; i++)  Left[i] = array[left + i];
    for (j = 0; j < nR; j++) Right[j] = array[mid  + j];
    
    Left[nL].id = Right[nR].id = SENTINEL;
    
    for (i = 0, j = 0, k = left; k < right; k++) {
        if (Left[i].id < Right[j].id) 
            array[k] = Left[i++];
        else 
            array[k] = Right[j++];
    }
}

void mergeSort(Node array[], int left, int right) {
    if (left + 1 < right) {
        int mid = (left + right)/2;
        mergeSort(array, left, mid);
        mergeSort(array, mid, right);
        merge(array, left, mid, right);
    }
}




int findArrayIndexWithValue(int array[], int length, int value) {
    for (int i = 0; i < length; i++)
        if (array[i] == value)
            return i;
    return NOT_FOUND;
}

int findNodeIndexWithId(Node nodes[], int length, int nodeId) {
    for (int i = 0; i < length; i++)
        if (nodes[i].id == nodeId)
            return i;
    return NOT_FOUND;
}

int findNodeIndexWithChildren(Node nodes[], int length, int cId) {
    for (int i = 0; i < length; i++) {
        if (nodes[i].id == cId) continue;

        if (findArrayIndexWithValue(nodes[i].children, nodes[i].nChildren, cId) != NOT_FOUND)
            return i;
    }
    return NOT_FOUND;
}

int depth(Node node) {
//    printf("depth");
    int i = 0;
    while (1) {
        i++;
        
        if (node.parentPointer == NULL || node.parentPointer->id == -1)
            return i;
        
        if (node.parentPointer->depth != NULL)
            return i + node.parentPointer->depth;
        
        node = *(node.parentPointer);
    }
}

int main(int argc, char** argv) {
    int nNodes, nChildren;
    scanf("%d", &nNodes);
    
    Node nodes[nNodes];
    int i, j;
    
    for (i = 0; i < nNodes; i++) {
        scanf("%d", &(nodes[i].id)); // id
        scanf("%d", &(nodes[i].nChildren)); // k, number of children
        
        nodes[i].depth = NULL;
        
        if (nodes[i].nChildren > 0)
            nodes[i].children = (int *)malloc(nodes[i].nChildren * sizeof(int));
        
        for (j = 0; j < nodes[i].nChildren; j++)
            scanf("%d", &(nodes[i].children[j]));
    }
    
    Node root;
    root.id = -1;
    int parentIndex;
    
    mergeSort(nodes, 0, nNodes);
//    int orderedIdList[nNodes];
//    quickSort(nodes, 0, nNodes - 1);
    
    
//    orderedIdList[0] = 0;
//    for (i = 0; i < nNodes; i++) {
//        for (j = 0; j < nNodes; j++) {
//            if (i == nodes[j].id) 
//                orderedIdList[i] = j;
//        }
//    }
//    printf("orderedIdList: ");printArray(orderedIdList, nNodes);printf("\n");
    
    // construct full tree of parents
    for (i = 0; i < nNodes; i++) {
        parentIndex = findNodeIndexWithChildren(nodes, nNodes, nodes[i].id);
        
        if (parentIndex == NOT_FOUND)
            nodes[i].parentPointer = &root;
        else
            nodes[i].parentPointer = &nodes[parentIndex];
    }
    
//    for (i = 0; i < nNodes; i++) {
//        j = depth(nodes[i]);
//        nodes[i].depth = j;
//    }

//    for (j = 0; j < nNodes; j++) {
//        i = orderedIdList[j];
    for (i = 0; i < nNodes; i++) {
        j = depth(nodes[i]);
        nodes[i].depth = j;
        
        printf("node %d: parent = %d, depth = %d, ", nodes[i].id,nodes[i].parentPointer->id,depth(nodes[i]));
        
        // node types
        if (nodes[i].parentPointer->id == -1)
            printf("root, ");
        else if (nodes[i].nChildren > 0)
            printf("internal node, ");
        else 
            printf("leaf, ");
        
        // children
        printf("[");printArray(nodes[i].children, nodes[i].nChildren);printf("]\n");
    }
    
    return (EXIT_SUCCESS);
}


