#include<iostream>
#include<vector>
using namespace std;
struct Node{
	int id, parent, depth;
	vector<int>children;
};
int get_Depth(int i, Node T[]){
	int d=0;
	while(T[i].parent!=-1){
		i=T[i].parent;
		d++;
	}
	return d;
}
void getDepth(int n, Node T[]){
	for(int i=0; i<T[n].children.size(); i++){
		T[T[n].children[i]].depth=T[n].depth+1;
		getDepth(T[n].children[i], T);
	}
}
int main(){
	int n;
	cin>>n;
	Node T[n];
	for(int i=0; i<n; i++){
		T[i].parent=-1;
	}
	for(int i=0; i<n; i++){
		int idk, k;
		cin>>idk>>k;
		T[i].id=idk;
		for(int j=0; j<k; j++){
			int ch;
			cin>>ch;
			T[ch].parent=idk;
			T[idk].children.push_back(ch);
		}
	}
	for(int i=0; i<n; i++){
		//cout<<"node "<<T[i].nodeId<<": parent = "<<T[i].parent<<", depth = "<<T[i].depth<<", ";
		//cout<<"node "<<T[i].nodeId<<": parent = "<<T[i].parent<<", depth = "<<get_Depth(i, T)<<", ";
		cout<<"node "<<i<<": parent = "<<T[i].parent<<", depth = "<<get_Depth(i, T)<<", ";
		if(T[i].parent==-1){
			cout<<"root, [";
			if(T[i].children.size()==0)
				cout<<"]"<<endl;
			else{
				for(int j=0; j<T[i].children.size()-1; j++){
					cout<<T[i].children[j]<<", ";
				}
				cout<<T[i].children[T[i].children.size()-1]<<"]"<<endl;
			}
		}
		else if(T[i].children.size()>0){
			cout<<"internal node, [";
			for(int j=0; j<T[i].children.size()-1; j++){
				cout<<T[i].children[j]<<", ";
			}
			cout<<T[i].children[T[i].children.size()-1]<<"]"<<endl;
		}
		else{
			cout<<"leaf, []"<<endl;
		}
	}
	/*int id;
	for(int i=0; i<n; i++)
		if(T[i].parent==-1)
			id=i;
	getDepth(id, T);
	for(int i=0; i<n; i++){
		//cout<<"node "<<i<<": "<<"parent = "<<T[i].parent<<", depth = "<<get_Depth(i, T)<<", ";
		cout<<"node "<<i<<": "<<"parent = "<<T[i].parent<<", depth = "<<T[i].depth<<", ";
		if(T[i].parent==-1)	cout<<"root, [";
		else if(T[i].children.size()==0)	cout<<"leaf, [";
		else	cout<<"internal node, [";
		for(int j=0; j<T[i].children.size()-1; j++)
			cout<<T[i].children[j]<<", ";
		cout<<T[i].children[T[i].children.size()-1]<<"]";
		cout<<endl;
	}*/
	return 0;
}
/*#include<iostream>
#include<vector>
using namespace std;
struct tree{
	int nodeId;
	int parent;
	int depth;
	int degree;
	vector<int> child;
};
int getDepth(int id, tree T[]){
    int d=0;
    while(T[id].parent!=-1){
        id=T[id].parent;
        d++;
    }
    return d;
}
void calcDepth(tree T[], int root_id){
	for(int i=0; i<T[root_id].degree; i++){
		T[T[root_id].child[i]].depth=T[root_id].depth+1;
		calcDepth(T, T[root_id].child[i]);
	}
}
int main(){
	int n;
	cin>>n;
	tree T[n];
	for(int i=0; i<n; i++){
		T[i].parent=-1;
	}
	for(int i=0; i<n; i++){
		int id, k;
		cin>>id>>k;
		T[id].nodeId=id;
		T[id].degree=k;
		//int c[k];
		int child_id;
		for(int j=0; j<k; j++){
			cin>>child_id;
			T[id].child.push_back(child_id);
			T[child_id].parent=id;
		}
	}
	int root_id;
	for(int i=0; i<n; i++){
		if(T[i].parent==-1){
			root_id=i;
		}
	}
	T[root_id].depth=0;
	calcDepth(T, root_id);
	for(int i=0; i<n; i++){
		cout<<"node "<<T[i].nodeId<<": parent = "<<T[i].parent<<", depth = "<<getDepth(i, T)<<", ";
		if(T[i].parent==-1)	cout<<"root, [";
		else if(T[i].child.size()==0)	cout<<"leaf, [";
		else	cout<<"internal node, [";
		for(int j=0; j<T[i].child.size()-1; j++){
			cout<<T[i].child[j]<<", ";
		}
		cout<<T[i].child[T[i].child.size()-1]<<endl;
	}
	return 0;
}*/


Measured memory_bytes: 7832