import scala.io.StdIn.{readInt,readLine}
import scala.collection.mutable.ArrayBuffer

object Main {
  val NIL = -1

  class Node(var parent:Int = NIL,var left:Int = NIL,var right:Int = NIL) { }

  def main(args:Array[String]) = {
    val n = readInt
    val tree = (0 until n).map(_=>new Node).toArray

    for(i<-0 until n) {
      val s = readLine.split(" ").map(_.toInt)
      tree(s(0)).left = s(1)
      tree(s(0)).right = s(2)
      if(s(1) != NIL) tree(s(1)).parent = s(0)
      if(s(2) != NIL) tree(s(2)).parent = s(0)
    }

    def preOrder(id:Int):Unit = {
      if(id!=NIL) {
        print(" "+id)
        preOrder(tree(id).left)
        preOrder(tree(id).right)
      }
    }

    def inOrder(id:Int):Unit = {
      if(id!=NIL) {
        inOrder(tree(id).left)
        print(" "+id)
        inOrder(tree(id).right)
      }
    }

    def postOrder(id:Int):Unit = {
      if(id!=NIL) {
        postOrder(tree(id).left)
        postOrder(tree(id).right)
        print(" "+id)
      }
    }

    val root = tree.indexWhere(_.parent == NIL)

    println("Preorder")
    preOrder(root)
    println
    println("Inorder")
    inOrder(root)
    println
    println("Postorder")
    postOrder(root)
    println
  }
}