import scala.io.StdIn.{readInt, readLine};
object Main {
    def main(args: Array[String]): Unit = {
        val size = readInt;
        val t = new Tree(size);
        (0 until size).foreach { i =>
            readLine.split(" ").map(_.toInt) match {
                case Array(v, l, r) => t.add(v, l, r);
            }
        }
        println("Preorder");
        println(t.walkPreorder().mkString(" "));
        println("Inorder");
        println(t.walkInorder().mkString(" "));
        println("Postorder");
        println(t.walkPostorder().mkString(" "));
    }
}
class Tree(val size: Int) {
    lazy private val root = setRoot();
    private val tree = new Array[(Int, Int, Int)](size);
    
    def add(value: Int, left: Int, right: Int): Unit = {
        tree(value) = (value, left, right);
    }
    def setRoot(): Int = {
        def _go(index: Int, tmpRoot: Int): Int = if (index >= size) {
            tmpRoot;
        } else {
            tree(index) match {
                case (v, l, r) => if (tmpRoot == l || tmpRoot == r) _go(0, v) else _go(index + 1, tmpRoot);
                case _ => _go(index + 1, tmpRoot)
            }
        }
        _go(0, tree(0)._1)
    }
    
    def walkPreorder(): List[Int] = {
        def _go(index: Int, ret: List[Int]): List[Int] = {
            if (index == -1) {
                ret;
            } else {
                val (v, l, r) = tree(index);
                val retSelf = v :: ret;
                val retLeft = _go(l, retSelf);
                val retRight = _go(r, retLeft);
                retRight;
            }
        }
        _go(root, Nil).reverse;
    }
    def walkInorder(): List[Int] = {
        def _go(index: Int, ret: List[Int]): List[Int] = {
            if (index == -1) {
                ret;
            } else {
                val (v, l, r) = tree(index);
                val retLeft = _go(l, ret);
                val retSelf = v :: retLeft;
                val retRight = _go(r, retSelf);
                retRight
            }
        }
        _go(root, Nil).reverse;
    }
    def walkPostorder(): List[Int] = {
        def _go(index: Int, ret: List[Int]): List[Int] = {
            if (index == -1) {
                ret;
            } else {
                val (v, l, r) = tree(index);
                val retLeft = _go(l, ret);
                val retRight = _go(r, retLeft);
                val retSelf = v :: retRight;
                retSelf
            }
        }
        _go(root, Nil).reverse;
    }
}
