class BinaryTree
	class Node
		attr_accessor :parent, :left, :right, :depth, :height

	end

	def initialize
		@nodes = []
	end

	def add(id, left, right)
		@nodes[id] ||= Node.new
		@nodes[id].left  = left
		@nodes[id].right = right

		if left != -1
			@nodes[left] ||= Node.new
			@nodes[left].parent = id
		end

		if right != -1
			@nodes[right] ||= Node.new
			@nodes[right].parent = id
		end

		self
	end

	def preorder
		preorder_helper(find_root)
	end

	def inorder
		inorder_helper(find_root)
	end

	def postorder
		postorder_helper(find_root)
	end

	private
	def exist?(id)
		id && id != -1
	end

	def find_root
		@nodes.find_index { |node| node.parent == nil }
	end

	def preorder_helper(id)
		node = @nodes[id]
		result = [id]

		result.concat(preorder_helper(node.left)) if exist?(node.left)
		result.concat(preorder_helper(node.right)) if exist?(node.right)
		result
	end

	def inorder_helper(id)
		node = @nodes[id]
		result = []

		result.concat(inorder_helper(node.left)) if exist?(node.left)
		result << id
		result.concat(inorder_helper(node.right)) if exist?(node.right)
		result
	end

	def postorder_helper(id)
		node = @nodes[id]
		result = []

		result.concat(postorder_helper(node.left)) if exist?(node.left)
		result.concat(postorder_helper(node.right)) if exist?(node.right)
		result << id
	end

end

tree = BinaryTree.new
n = STDIN.gets.to_i
n.times do
	id, left, right = STDIN.gets.split[0..2].map(&:to_i)
	tree.add(id, left, right)
end

puts "Preorder"
puts " #{tree.preorder.join(" ")}"
puts "Inorder"
puts " #{tree.inorder.join(" ")}"
puts "Postorder"
puts " #{tree.postorder.join(" ")}"