n = gets.chomp.to_i
class TreeWalk
	attr_accessor :right, :left, :parent

	def initialize(left=-1,right=-1, parent = -1)
		@right = right
		@left = left
		@parent = parent
	end
end
$nodes = []

n.times{|i|$nodes[i] = TreeWalk.new}
n.times do
	id, left, right = gets.chomp.split(" ").map{|i|i.to_i}
	$nodes[id].left = left; $nodes[id].right = right
	$nodes[left].parent = id if left != -1
	$nodes[right].parent = id if right != -1
end
	def preorder(id)
		print " #{id}"
		preorder($nodes[id].left) if $nodes[id].left != -1
		preorder($nodes[id].right) if $nodes[id].right != -1
	end
	
	def inorder(id)
		inorder($nodes[id].left) if $nodes[id].left != -1
		print " #{id}"
		inorder($nodes[id].right) if $nodes[id].right != -1
	end
	
	def postorder(id)
		postorder($nodes[id].left) if $nodes[id].left != -1
		postorder($nodes[id].right) if $nodes[id].right != -1
		print " #{id}"
	end
	id = 0
	$nodes.each_with_index do |node,ix|
		if node.parent == -1
			id = ix
			break
		end
	end
puts "Preorder"
preorder(id)
print "\n"
puts "Inorder"
inorder(id)
print "\n"
puts "Postorder"
postorder(id)
print "\n"

