n = gets.to_i
node = Array.new(n)
parent = Array.new(n,-1)
sibling = Array.new(n,-1)
degree = Array.new(n,0)
depth = Array.new(n)
height = Array.new(n)

n.times do
  l = gets.split.map(&:to_i)
  node[l[0]] =  l[1,2]
end
n.times do |i|
  a, b = node[i]
  parent[a] = i if a != -1
  parent[b] = i if b != -1
  sibling[a] = b if a != -1 && b != -1
  sibling[b] = a if a != -1 && b != -1
  degree[i] = 2 - [a,b].count(-1)
end
depth[p = parent.index(-1)] = 0
cnt = 0
while depth.any?{|v| v.nil?}
  n.times do |i|
    if depth[i] == cnt
      a, b = node[i]
      depth[a] = cnt + 1 if a != -1
      depth[b] = cnt + 1 if b != -1
    end
  end
  cnt += 1
end
n.times{ |i| height[i] = 0 if degree[i] == 0 }
cnt = 0
while true
  f = false
  n.times do |i|
    if height[i] == cnt 
      next if parent[i] == -1 
      height[parent[i]] = cnt + 1
      f = true
    end
  end
  break unless f 
  cnt += 1
end
type = Array.new(n)
n.times{|i| type[i] = parent[i] == -1 ? "root" : node[i].count(-1) == 2 ? "leaf" : "internal node"}
n.times{|i| puts "node #{i}: parent = #{parent[i]}, sibling = #{sibling[i]}, degree = #{degree[i]}, depth = #{depth[i]}, height = #{height[i]}, #{type[i]}"}