n=*0...gets.to_i
g=$<.map{|l|l.split.map &:to_i}.select{|v|v[0]}.sort
r=n.-g.map{|v|v[1,2]}.reduce:+
x,y,*z=[],[]
w=->f,i{i<0&&next
x<<i
f[f,g[i][1]]
y<<i
f[f,g[i][2]]
z<<i}
w[w,r[0]]
s=" "
puts :Preorder,s+x*s,:Inorder,s+y*s,:Postorder,s+z*s