#rooted_tree
class Node
  attr_accessor :myname,:parent,:children,:depth

  def initialize(my)
    @myname = my
    @parent = -1
    @children = Array.new
    @child_count = 0
  end

  def add_child(child)
    children << child
    child.parent= self
  end

  def print_child
    cc = self.children.length
    printf(", [")
    0.upto(cc-1){|i|
      printf("%s",self.children[i])
      printf(", ") if i < cc-1
    }
    printf("]")
  end

  def print_parent
    printf("%s",self.parent)
  end

  def to_s
    "#@myname"
  end

  def set_depth(d)
    self.depth=d
    for c in self.children
      c.set_depth(d+1)
    end
  end

  def shubetu
    if self.parent == -1
      "root"
    elsif children.length == 0
      "leaf"
    else
      "internal node"
    end
  end

  def describe
    printf("node %s: parent = %s,",self.myname,self.parent)
    printf(" depth = %d,",self.depth)
    printf(" %s",self.shubetu)
    self.print_child
    printf("\n")
  end

end


n = STDIN.gets.split[0].to_i
tree=Array.new
0.upto(n-1){|i|
  tree[i]=Node.new(i)
}


0.upto(n-1){|i|
  s = STDIN.gets.split
  id= s[0].to_i
  cc= s[1].to_i
  p=2
  cc.times{
    #puts tree[s[id].to_i]
    tree[i].add_child(tree[s[p].to_i])
    p += 1
  }
}

def findroot(tree,n)
  0.upto(n-1){|i|
    if tree[i].parent == -1 
      return i
    end
  }
end 

tree[findroot(tree,n)].set_depth(0)

0.upto(n-1){|i|
  tree[i].describe
}