module Main where

import Debug.Trace
import Data.List
import qualified Data.Sequence as S
import qualified Data.ByteString.Char8 as B
import Data.Int
import Data.Char
import Data.Array
import Data.Maybe
import qualified Data.Map as M
import Data.Ord
import Data.Functor
import Control.Applicative
import Control.Monad
import Text.Printf

data Tree = Nil | Node Int Tree Tree deriving (Eq, Show)

solve :: Int -> [[Int]] -> ([Int], [Int], [Int])
solve n lst = (preorder, inorder, postorder) where
    preorder = iter root where
        iter Nil = []
        iter (Node id left right) = id:iter left ++ iter right    

    inorder = iter root where
        iter Nil = []
        iter (Node id left right) = iter left ++ id:iter right

    postorder = iter root where
        iter Nil = []
        iter (Node id left right) = iter left ++ iter right ++ [id]    

    root = iter rootId where
        iter (-1) = Nil
        iter x = Node x (iter l) (iter r) where
            (l, r) = treeTbl!x  

    (treeTbl, rootId) = iter 0 [] lst where
        iter s ac [] = ((listArray (0, n-1) (replicate n (-1, -1))) // ac, div (n*(n-1)) 2 - s)
        iter s ac ([x,(-1),(-1)]:ns) = iter s ac ns 
        iter s ac ([x,l,(-1)]:ns) = iter (s+l) ((x, (l, -1)):ac) ns 
        iter s ac ([x,(-1),r]:ns) = iter (s+r) ((x, (-1, r)):ac) ns 
        iter s ac ([x,l,r]:ns) = iter (s+l+r) ((x, (l, r)):ac) ns

readIntLn:: IO Int
readIntLn = (fst . fromJust . B.readInt) <$> B.getLine

readIntList:: IO [Int]
readIntList = map (fst . fromJust . B.readInt) . B.words <$> B.getLine

print' [] = putStrLn ""
print' (x:xs) = do
    putStr $ ' ':(show x)
    print' xs

main :: IO() 
main = do
    n <- readIntLn
    l <- replicateM n readIntList
    let (pro, ino, poo) = solve n l
    putStrLn "Preorder"
    print' pro
    putStrLn "Inorder"
    print' ino
    putStrLn "Postorder"
    print' poo

