class Node
  def initialize(id, key)
    @id = id
    @key = key
    @parent = nil
    @left = nil
    @right = nil
  end

  def print_self
    print "node #{@id}: "
    print "key = #{@key}, " unless @key == nil
    print "parent key = #{@parent}, " unless @parent == nil
    print "left key = #{@left}, " unless @left == nil
    print "right key = #{@right}, " unless @right == nil
    print "\n"
  end

  attr_accessor :id, :key, :parent, :left, :right
end

n = gets.chomp.to_i
input = gets.chomp.split.map(&:to_i)
array = ["dummy"]
input.each_with_index do |key, id|
  next if key == "dummy"
  id += 1
  node = Node.new(id, key)
  if (id/2) > 0 then
    node.parent = array[id/2].key 
    if (id % 2) == 0 then
      array[id/2].left = node.key
    else
      array[id/2].right = node.key
    end
  end
  array << node
end

array.shift
array.each do |node|
  node.print_self
end