import Control.Monad
import Control.Applicative
import Data.Array.IArray

data Tree = Leaf | Branch Int Tree Tree
          deriving (Show)
type Info = Array Int (Int, Int)

main :: IO ()
main = do
  n <- readLn :: IO Int
  ns <- replicateM n $ do
    [c, l, r] <- getInts
    return (c, (l, r))
  let info =
        accumArray (\_ c -> c) (-1, -1) (0, n-1) ns :: Info
      tree = makeTree info
      ans = map (\a -> unwords $ map show $ a tree) [pre, inor, post]
      header = ["Preorder", "Inorder", "Postorder"]
  mapM_ (putStrLn . (\(h, a) -> h ++ "\n " ++ a)) $ zip header ans

getInts :: IO [Int]
getInts = map read . words <$> getLine

makeTree :: Info -> Tree
makeTree arr = go 0
  where
    go (-1) = Leaf
    go n = let (l, r) = arr ! n in
             Branch n (go l) (go r)

pre :: Tree -> [Int]
pre Leaf = []
pre (Branch n l r) = n : pre l ++ pre r

inor :: Tree -> [Int]
inor Leaf = []
inor (Branch n l r) = inor l ++ [n] ++ inor r

post :: Tree -> [Int]
post Leaf = []
post (Branch n l r) = post l ++ post r ++ [n]