#include<stdio.h>
#define MAX 100005
#define NIL -1
 
struct Node{
int p, l, r;
};
struct Node Tree[MAX];
int n;

int main(){
  int a, c, d, i, j, l, v;
 
  scanf("%d", &n);
 
  for(i = 0; i < n; i++) Tree[i].p = Tree[i].l = Tree[i].r = NIL;
 
  for(i = 0; i < n; i++){
    scanf("%d %d", &v, &d);
    for(j = 0;j < d; j++){
      scanf("%d", &c);
      Tree[c].p = v;
      if(j == 0) Tree[v].l = c;
      else Tree[a].r = c;
      a = c;
    }
  }
  for(i = 0; i < n; i++) printf("%d", i);

  return 0;
}



int getDepth(int u){
  int d = 0, i;

  for(i = u;Tree[i].p != NIL; i = Tree[i].p, d++);

  return d;
}
 
void print(int u){

  int b = getDepth(u), c = Tree[u].l;

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

  if(b == 0) printf("root, ");
  else if (Tree[u].l != NIL) printf("internal node, ");
  else printf("leaf, ");
  printf("[");
  if(Tree[u].l==NIL) printf("]\n");
  else {
    while(1){
      printf("%d", c);
      if(Tree[c].r == NIL){
    printf("]\n");
    break;
      }
      else printf(", ");
      c = Tree[c].r;
    }
  }
}