#!/usr/bin/env ruby

def make_tree(input)
  tree = []
  lines = parse_input(input)
  lines.each do |line|
    tree[line[0]] = { parent: -1, children: line[2..-1] }
  end
  tree.each_with_index do |node, index|
    node[:children].each do |child|
      tree[child][:parent] = index
    end
  end
  root_index = tree.find_index { |node| node[:parent] == -1 }
  set_type(tree)
  set_depth(root_index, 0, tree)
  printable_tree(tree)
end

def set_type(tree)
  tree.each do |node|
    if node[:parent] == -1
      node[:type] = :root 
    elsif node[:children] == []
      node[:type] = :leaf
    else 
      node[:type] = :internal_node
    end
  end
end

def set_depth(node_index, depth, tree)
  tree[node_index][:depth] = depth
  tree[node_index][:children].each { |child_index| set_depth(child_index, depth+1, tree) }
end

def printable_tree(tree)
  out = []
  tree.each_with_index do |node, index|
    out << "node #{index}: parent = #{node[:parent]}, depth = #{node[:depth]}" +
      ", #{node[:type].to_s.sub('_', ' ')}, #{node[:children].nil? ? [] : node[:children]}"
  end
  out.join("\n")+"\n"
end

def parse_input(input)
  lines = input.split("\n")
  lines[1..-1].map(&:split).map{|line| line.map(&:to_i)}
end

INPUT_1=<<EOS
13
0 3 1 4 10
1 2 2 3
2 0
3 0
4 3 5 6 7
5 0
6 0
7 2 8 9
8 0
9 0
10 2 11 12
11 0
12 0
EOS

OUTPUT_1=<<EOS
node 0: parent = -1, depth = 0, root, [1, 4, 10]
node 1: parent = 0, depth = 1, internal node, [2, 3]
node 2: parent = 1, depth = 2, leaf, []
node 3: parent = 1, depth = 2, leaf, []
node 4: parent = 0, depth = 1, internal node, [5, 6, 7]
node 5: parent = 4, depth = 2, leaf, []
node 6: parent = 4, depth = 2, leaf, []
node 7: parent = 4, depth = 2, internal node, [8, 9]
node 8: parent = 7, depth = 3, leaf, []
node 9: parent = 7, depth = 3, leaf, []
node 10: parent = 0, depth = 1, internal node, [11, 12]
node 11: parent = 10, depth = 2, leaf, []
node 12: parent = 10, depth = 2, leaf, []
EOS

INPUT_2=<<-EOS
4
1 3 3 2 0
0 0
3 0
2 0
EOS

OUTPUT_2=<<-EOS
node 0: parent = 1, depth = 1, leaf, []
node 1: parent = -1, depth = 0, root, [3, 2, 0]
node 2: parent = 1, depth = 1, leaf, []
node 3: parent = 1, depth = 1, leaf, []
EOS

# puts make_tree(INPUT_1)==OUTPUT_1
# puts make_tree(INPUT_2)==OUTPUT_2

puts make_tree(STDIN.read)