n = gets.chomp.to_i
nodes = {}
ps = []
lrs = []
n.times do
    p, l, r = gets.chomp.split.map(&:to_i)
    nodes[p] = { p: p, l: l, r: r }
    ps.push(p)
    lrs.push(l, r)
end
Nodes = nodes
lrs.uniq!.sort!
root = (ps - lrs)[0]

def preParse(u)
    return if u == -1
    print " #{u}"
    preParse(Nodes[u][:l])
    preParse(Nodes[u][:r])    
end

def inParse(u)
    return if u == -1
    inParse(Nodes[u][:l])
    print " #{u}"
    inParse(Nodes[u][:r])
end

def postParse(u)
    return if u == -1
    postParse(Nodes[u][:l])
    postParse(Nodes[u][:r])
    print " #{u}"
end

puts "Preorder"
preParse(root)
puts ""

puts "Inorder"
inParse(root)
puts ""

puts "Postorder"
postParse(root)
puts ""
