class Node
  attr_accessor :id, :left, :right, :parent, :sibling
  def initialize(id,left=nil,right=nil)
    @id,@left,@right=id,left,right
    @sibling,@parent=nil,nil
  end

  def height
    return -1 if @id==-1
    return @left.height<@right.height ? @right.height+1 : @left.height+1
  end

  def depth
    return 0 if @id==0
    return @parent.depth+1
  end

  def type
    if @left.id==-1 && @right.id==-1
      return "leaf"
    elsif @parent.id==-1
      return "root"
    else
      return "internal node"
    end
  end

  def degree
    if @left.id>=0&&@right.id>=0
      return 2
    elsif @left.id==-1&&@right.id==-1
      return 0
    else
      return 1
    end
  end
end

n=gets.to_i
nodes=[]
(0..n-1).each do |i|
  id,l,r=gets.split.map(&:to_i)
  nodes[id]=Node.new(id,l,r)
end
root=nodes[0]
root.sibling,root.parent=Node.new(-1),Node.new(-1)

nodes.each do |i|
  i.left=i.left==-1?Node.new(-1):nodes[i.left]
  i.right=i.right==-1?Node.new(-1):nodes[i.right]
  i.left.sibling,i.right.sibling=i.right,i.left
  i.left.parent=i.right.parent=i
end

(0..nodes.size-1).each do |i|
  ans="node #{i}: parent = #{nodes[i].parent.id}"
  puts ans

end