////////////////////////////////////////
//ALDS1_7_A:   Rooted Trees
//
//left-child, right-sibling representation
//??§????????°???Node???????????????????????§?°?????????§??????
////////////////////////////////////////

#include <iostream>
#include <algorithm> // next_permutation
#include <iomanip>
#include <cmath>
#include <vector>
#include <sstream>
#include <string>
#include <cstdio>
#include <stack>
#include <queue>
#include <list>
#include <numeric> //accumulate
//#include <unordered_map> //???????????\??¢??°
#include <fstream> //ifstream, ofstream

//#define NDEBUG //NDEBUG???#include <cassert>???????????????????????????????????´???assert?????????????????????????????????NDEBUG?????????????????????????????????????????????
#include <cassert> //assert


using namespace std;

//???????????°??????TEST????????????????????¬???????????????????????????????????¢????????????
#define TEST //*******************************************************************************************************************************************
//?????????????????¨??§?????\????????????????????????????????°?????????????¨???????????????????dout???????????????????????§???????????¬??????????????????????????????????????????
//??????????????????????????????????????????????????????????§?CPU???????£??????????????????§???TLE?????????????????????????????????????????§????????¨???                           ????????????????????????cerr????????£????????????????????????????????????
#ifdef TEST
#define dout cout
#else
stringstream dummy; //???????????°??????dout?????????????????????????????????
#define dout dummy.str(""); dummy.clear(stringstream::goodbit); dummy //dummy?????????????????????????????????????????¨?????¢?????¢???????????????
//???????????¨??????????????????goodbit?????????????????????????????¨???????????´????????????????????????????????¨?????°?????????????????§???????????????????????????????????? http://d.hatena.ne.jp/linden/20060427/p1
#endif

//?¨??????????????????????????????????????????????????????´??????OUTPUT2TEXTFILE????????????????????¬???????????????????????????????????¢????????????
//#define OUTPUT2TEXTFILE //*******************************************************************************************************************************************
#ifdef OUTPUT2TEXTFILE
#define dout outputfile //??¨????????????TLE????????§?????????dout?????¨??¨??????????????¢????????????????????????????????????????????§????¨????????????´??????????????£??????????????????????¨?????????????????????????????????????????????§?????????????????????
//TEST??????????????????????????¨???outputfile??????????????????????????????
#define OUTPUTFILENAME "output.txt"
ofstream outputfile(OUTPUTFILENAME);
#define OutputFilePath "/Users/Nag/Documents/Prgm/Test/DerivedData/Test/Build/Products/Debug/output.txt"
#endif

#define disp(A) dout << #A << " = " << (A) << endl
#define disP(A) dout << setw(3) << (A) << " " // << setw(3) ??????????????\????????????
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)

#define dispAll(A,n) dout << #A << " = "; rep(j, 0, (n)) {disP(A[j]);} dout << endl

typedef pair<int,int> pii;
typedef vector<int> vi;
typedef unsigned long long ll;

const int INF = 1e9-1;

class Node;

vector<Node> node;


class Node {
public:
    Node() {
        parent = -1;
        leftChild = -1;
        rightSibling = -1;
    }
    
    int parent;
    int leftChild;
    int rightSibling;
    
    
    int depth() {
        int p = this->parent;
        int d = 0;
        
        while( p != -1 ) {
            d++;
            p = node[p].parent;
        }
        
        return d;
    }
    
    void printChild() {
        int c = this->leftChild;
        if( c==-1 ) return;
        else {
            cout << c;
        }
        
        c = node[c].rightSibling;
        
        while( c!=-1 ) {
            cout << ", " << c;
            c = node[c].rightSibling;
        }
    }
};



int main(){
    int N; cin >> N;
    rep(i,0,N) node.push_back(*new Node());

    //read input data
    int p, numOfChild, c, c_prev = -1;
    rep(i,0,N) {
//        dout<<"------";
//        disp(i);
        cin >> p >> numOfChild;
        
        rep(j,0,numOfChild) {
//            disp(j);
            cin >> c;
//            disp(c);
            
            if( j==0 ) node[p].leftChild = c;
            else {
                assert(c_prev!=-1);
                node[c_prev].rightSibling = c;
            }
            
            node[c].parent = p;
            c_prev = c;
        }
    }
    
  
//    //test display
//    rep(i,0,N) {
//        disP(i);
//        disP(node[i].leftChild); disP(node[i].rightSibling); disP(node[i].parent);
//        dout << endl;
//    }
    
    
    //output
    rep(i,0,N) {
        cout << "node " << i << ": parent = " << node[i].parent << ", depth = " << node[i].depth() << ", "
            << (node[i].parent==-1 ? "root" : (node[i].leftChild==-1 ? "leaf" : "internal node") ) << ", [";
        
        node[i].printChild();
        
        cout << "]" << endl;
    }

    
    
#ifdef OUTPUT2TEXTFILE
    outputfile.close();
    cout << "\"" << OutputFilePath << "\"" << endl;
#endif
    
    return 0;
}

Measured memory_bytes: 6960