NONE = -1

class Node
	attr_accessor :p, :l, :r
	def initialize(p, l, r)
		@p = p; @l = l; @r = r
	end
end

$t = []

def preParse(u)
	return if u == NONE
	printf(" %d", u)
	preParse($t[u].l)
	preParse($t[u].r)
end

def inParse(u)
	return if u == NONE
	inParse($t[u].l)
	printf(" %d", u)
	inParse($t[u].r)
end

def postParse(u)
	return if u == NONE
	postParse($t[u].l)
	postParse($t[u].r)
	printf(" %d", u)
end

n = gets.to_i
0...n.times do |i|
	$t[i] = Node.new(NONE, NONE, NONE)
end
0...n.times do |i|
	v, l, r = gets.split.map &:to_i
	$t[v].l = l
	$t[v].r = r
	$t[l].p = v if l != NONE
	$t[r].p = v if r != NONE
end
root = 0
0...n.times do |i|
	root = i if $t[i].p == NONE
end

printf("Preorder\n")
preParse(root)
puts
printf("Inorder\n")
inParse(root)
puts
printf("Postorder\n")
postParse(root)
puts