import Data.List
import Control.Monad.Writer

data Tree a = EmptyTree | Node a (Tree a) (Tree a) deriving (Show)

findRoot :: Int -> [(Int, (Int, Int))] -> Int
findRoot x xs = let
                  findLR (idx, (l, r)) = l == x || r == x
                  node = find findLR xs
                in
                  case node of
                    Just (idx, _) -> findRoot idx xs
                    Nothing       -> x

makeTree :: Int -> [(Int, (Int, Int))] -> Tree Int
makeTree x xs = let
                  node = lookup x xs
                in
                  case node of
                    Just (l, r) -> Node x (makeTree l xs) (makeTree r xs)
                    Nothing            -> EmptyTree

preorder :: Tree Int -> Writer [Int] (Tree Int)
preorder EmptyTree = return (EmptyTree)
preorder (Node idx l r) = do
  tell [idx]
  preorder l
  preorder r

inorder :: Tree Int -> Writer [Int] (Tree Int)
inorder EmptyTree = return (EmptyTree)
inorder (Node idx l r) = do
  inorder l
  tell [idx]
  inorder r

postorder :: Tree Int -> Writer [Int] (Tree Int)
postorder EmptyTree = return (EmptyTree)
postorder (Node idx l r) = do
  postorder l
  postorder r
  tell [idx]
  return (EmptyTree)

format :: [Int] -> String
format xs = foldl (\acc x -> acc ++ " " ++ show x) "" xs

main = do
  n <- fmap (read) getLine
  lns <- sequence $ replicate n getLine
  let nodes = map ((\[x,y,z] -> (x, (y,z))) . map read . words) lns
      r = findRoot (fst (nodes !! 0)) nodes
      tree = makeTree r nodes
  putStrLn "Preorder"
  putStrLn $ format . snd . runWriter $ preorder tree
  putStrLn "Inorder"
  putStrLn $ format . snd . runWriter $ inorder tree
  putStrLn "Postorder"
  putStrLn $ format . snd . runWriter $ postorder tree