import scala.io.StdIn

object Main extends App {

  final val nil = -1
  
  case class Node(var parent: Int = -1,var left: Int = -1, var right: Int = -1)

  val n = StdIn.readLine().trim.toInt
  val input  = Array.fill[Node](n)(Node())
  val depth  = Array.fill[Int](n)(0)
  val height = Array.fill[Int](n)(0)

  (0 until n).foreach{ _ =>
    val Array(current, left, right) = StdIn.readLine().trim.split(" ").map(_.toInt)
    input(current).left = left
    input(current).right = right
    if(left != nil) input(left).parent = current
    if(right != nil) input(right).parent = current
  }

  var root = nil
  (0 until n).foreach{ i =>
    //println(s"$i:" + input(i))
    if(input(i).parent == nil) root = i
  }
  
  def preorder(index: Int): Unit = {
    if(index != nil) {
      print(" " + index)
      preorder(input(index).left)
      preorder(input(index).right)
    }
  }

  def inorder(index: Int): Unit = {
    if(index != nil){
      inorder(input(index).left)
      print(" " + index)
      inorder(input(index).right)
    }
  }

  def postorder(index: Int): Unit = {
    if(index != nil) {
      postorder(input(index).left)
      postorder(input(index).right)
      print(" " + index)
    }
  }
  
  println("Preorder")
  preorder(root)
  println("")

  println("Inorder")
  inorder(root)
  println("")

  println("Postorder")
  postorder(root)
  println("")

}
