import scala.io.StdIn.{readInt, readLine};

object Main {
    def main(args: Array[String]): Unit = {
        val n = readInt;
        val tree = new TreeWalk(n);
        for (i <- (0 until n)) {
            val line = readLine.split(" ").map(_.toInt);
            tree.add(line(0), line(1), line(2));
        }
        println("Preorder");
        println(" " + tree.preorder.mkString(" "));
        println("Inorder");
        println(" " + tree.inorder.mkString(" "));
        println("Postorder");
        println(" " + tree.postorder.mkString(" "));
    }
}
class TreeWalk(size: Int) {
    case class Node(id: Int, var parent: Node, var left: Node, var right: Node);
    val tree = new Array[Node](size);
    lazy val root: Option[Node] = tree.find(a => a != null && a.parent == null);
    def add(id: Int, left: Int, right: Int): Unit = {
        if (tree(id) == null) tree(id) = Node(id, null, null, null);
        if (left != -1) {
            if (tree(left) == null) tree(left) = Node(left, null, null, null);
            tree(left).parent = tree(id);
            tree(id).left = tree(left);
        }
        if (right != -1) {
            if (tree(right) == null) tree(right) = Node(right, null, null, null);
            tree(right).parent = tree(id);
            tree(id).right = tree(right);
        }
    }
    def preorder: List[Int] = {
        def go(curr: Node, ret: List[Int]): List[Int] = {
            if (curr == null) {
                ret;
            } else {
                val ret1 = curr.id :: ret;
                val ret2 = go(curr.left, ret1);
                val ret3 = go(curr.right, ret2);
                ret3;
            }
        }
        root match {
            case None => Nil;
            case Some(r) => go(r, Nil).reverse;
        }
    }
    def inorder: List[Int] = {
        def go(curr: Node, ret: List[Int]): List[Int] = {
            if (curr == null) {
                ret;
            } else {
                val ret1 = go(curr.left, ret);
                val ret2 = curr.id :: ret1;
                val ret3 = go(curr.right, ret2);
                ret3;
            }
        }
        root match {
            case None => Nil;
            case Some(r) => go(r, Nil).reverse;
        }
    }
    def postorder: List[Int] = {
        def go(curr: Node, ret: List[Int]): List[Int] = {
            if (curr == null) {
                ret;
            } else {
                val ret1 = go(curr.left, ret);
                val ret2 = go(curr.right, ret1);
                val ret3 = curr.id :: ret2;
                ret3;
            }
        }
        root match {
            case None => Nil;
            case Some(r) => go(r, Nil).reverse;
        }
    }
}
