class Node
  attr_accessor :id, :key, :parent, :left, :right

  def initialize(id, n, parent)
    @id = id
    @key = nil
    @parent = parent
    @left  = Node.new(id*2  , n, self) if id*2   <= n
    @right = Node.new(id*2+1, n, self) if id*2+1 <= n
  end
  
  def set_key(id, key)
    n = self
    visited = [n]
    while not visited.empty?
      n = visited.shift
      # begin -------
      if not n.key
        n.key = key
        break
      end
      # end   -------
      visited << n.left if n.left
      visited << n.right if n.right
    end
  end
  
  def out
    n = self
    visited = [n]
    while not visited.empty?
      n = visited.shift
      # begin -------
      print "node #{n.id}: "
      print "key = #{n.key}, "
      print "parent key = #{n.parent.key}, " if n.parent
      print "left key = #{n.left.key}, " if n.left
      print "right key = #{n.right.key}, " if n.right
      puts ''
      # end   -------
      visited << n.left if n.left
      visited << n.right if n.right
    end
  end

end

n = gets.to_i
root = Node.new(1, n, nil)

keys = gets.split.map(&:to_i)
n.times do | i |
  root.set_key(i, keys[i])
end

root.out

