gets
c=[]
l=$<.map{|t|i=t.split.map &:to_i;c[i[1]]=c[i[2]]=1;i}.sort
f=->n,a{n<0||a.map{|j|j<1?(print " ",n):f[l[n][j],a]}}
(0..2).map{|i|puts %w(Pre In Post)[i]+"order";a=[1,2];a[i,0]=[0];f[c.index(p)||-1,a];puts}