// Original C++ solution (slower):
#include <cstdio>

#include <cstring>

#include <algorithm>

#include <iostream>

#include <vector>

using namespace std;

const int maxn=100005;

struct tree

{

    int parent;

    vector<int>child;

    int depth;

};

tree node[maxn];

int n;

void init()

{

    for (int i=0;i<n;i++)

        node[i].depth=node[i].parent=-1;

}

int Find (int x)

{

    if(node[x].parent==-1)

        return node[x].depth=0;

    else if(node[x].depth!=-1)

        return node[x].depth;

    else

        return Find(node[x].parent)+1;

}

int main()

{

    scanf("%d",&n);

    init();

    for (int i=0;i<n;i++)

    {

        int x,num;

        scanf("%d%d",&x,&num);

        while (num--)

        {

            int y;

            scanf("%d",&y);

            node[y].parent=x;

            node[x].child.push_back(y);

        }

    }

    for (int i=0;i<n;i++)

    {

        printf("node %d: parent = %d, depth = %d, ",i,node[i].parent,node[i].depth=Find(i));

        if(node[i].parent==-1)

            printf("root, ");

        else if(!node[i].child.size())

            printf("leaf, ");

        else

            printf("internal node, ");

        printf("[");

        for (int j=0;j<node[i].child.size();j++)

        {

            printf("%d",node[i].child[j]);

            if(j<node[i].child.size()-1)

                printf(", ");

        }

        printf("]\n");

    }

    return 0;

}




// Optimized solution to the same problem (faster):
#include<iostream>

#include<cstdio>

#include<algorithm>

#include<cmath>

using namespace std;

const int MAX = 100005;

const int NIL = -1;





struct Node {

    int p, l, r;

};

Node Tree[MAX];

int n, Depth[MAX];





void print(int u) {

    printf("node %d: ", u);

    printf("parent = %d, ", Tree[u].p);

    printf("depth = %d, ", Depth[u]);



    if (Tree[u].p == NIL)

        printf("root, ");

    else if (Tree[u].l == NIL)

        printf("leaf, ");

    else

        printf("internal node, ");



    printf("[");

    // 浠庡瓙缁撶偣鐨勬渶宸﹁竟寮€濮嬮亶鍘?

    int c = Tree[u].l;

    while (c != NIL) {

        printf("%d", c);

        if (Tree[c].r != NIL)

            printf(", ");

        // 璺冲埌鍙充晶绱ч偦鐨勫厔寮熺粨鐐?

        c = Tree[c].r;

    }

    printf("]\n");

}



// 閫掑綊寰楁眰娣卞害

void rec(int u, int depth) {

    Depth[u] = depth;

    if (Tree[u].r != NIL)  // 鍙充晶鍏勫紵璁剧疆涓虹浉鍚屾繁搴?

        rec(Tree[u].r, depth);

    if (Tree[u].l != NIL)  // 鏈€宸︿晶瀛愮粨鐐圭殑娣卞害璁剧疆涓鸿嚜宸辩殑娣卞害 + 1

        rec(Tree[u].l, depth + 1);

}

int main() {

    int n;

    scanf("%d", &n);



    for (int i = 0; i < n; i++) {

        Tree[i].p = Tree[i].l = Tree[i].r = NIL;

    }

    int v, num, c, l, root;

    for (int i = 0; i < n; i++) {

        // v鏄綋鍓嶇粨鐐瑰€?锛宯um鏄痸缁撶偣鐨勫瓙缁撶偣鏁?

        scanf("%d %d", &v, &num);

        for (int j = 0; j < num; j++) {

            scanf("%d", &c);



            //璁剧疆鏈€宸︿晶缁撶偣 鍜?绱ч偦鍙充晶鍏勫紵缁撶偣

            // l璁板綍鐨勬槸涓婁竴涓粨鐐癸紝灏嗗綋鍓嶇殑缁撶偣璁剧疆涓簂鐨勭揣閭诲彸渚х粨鐐?

            if (j == 0)

                Tree[v].l = c;

            else

                Tree[l].r = c;

            l = c;

            // 璁剧疆鐖剁粨鐐?

            Tree[c].p = v;

        }

    }

    // 鎵惧嚭鏍圭粨鐐?

    for (int i = 0; i < n; i++) {

        if (Tree[i].p == NIL)

            root = i;

    }



    rec(root, 0);

    for (int i = 0; i < n; i++)

        print(i);

    return 0;

}


// Fastest known solution for this problem: