using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        public class Node
        {
            public int id;
            public int parent = -1;
            public int left = -1;
            public int right = -1;
            public int sibling= -1;
            public int height;
            public int depth;
        }
        static void Main(string[] args)
        {
            SolveA(args);
            //SolveB(args);
            //SolveC(args);
            //SolveD(args);


        }
        static void SolveA(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            Node[] nodes = new Node[n];
            for(int i = 0; i < nodes.Length; ++i) { nodes[i] = new Node(); }
            for (int i = 0; i < n; ++i)
            {
                int[] arr = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
               
                int id = arr[0];
                int l = arr[1];
                int r = arr[2];
                nodes[id].id = id;
                nodes[id].left = l;
                nodes[id].right = r;
                if (l != -1)
                {
                    nodes[l].parent = id;
                    nodes[l].sibling = r;
                }
                if (r != -1)
                {
                    nodes[r].parent = id;
                    nodes[r].sibling = l;
                }
            }
            Node rootnode = nodes.First(p => p.parent == -1);
            SetDepth(nodes, rootnode);
            SetHeight(nodes, rootnode);

            Console.WriteLine("Preorder");
            PreParse(nodes, rootnode.id);
            Console.WriteLine();
            Console.WriteLine("Inorder");
            InParse(nodes, rootnode.id);
            Console.WriteLine();
            Console.WriteLine("Postorder");
            PostParse(nodes, rootnode.id);
            Console.WriteLine();
        }
        private static void SetDepth(Node[] nodes, Node parent)
        {
            if(parent.left != -1)
            {
                nodes[parent.left].depth = parent.depth + 1;
                SetDepth(nodes, nodes[parent.left]);
            }
            if(parent.right != -1)
            {
                nodes[parent.right].depth = parent.depth + 1;
                SetDepth(nodes, nodes[parent.right]);

            }
        }
        private static int SetHeight(Node[] nodes, Node parent)
        {
            int h1 = 0;
            int h2 = 0;
            if (parent.left != -1)
            {
                h1 = SetHeight(nodes, nodes[parent.left]) + 1;
            }
            if (parent.right != -1)
            {
                h2 = SetHeight(nodes, nodes[parent.right]) + 1;
            }
            int h = Math.Max(h1, h2);
            parent.height = h;
            return h;
        }
        private static void PreParse(Node[] nodes, int p)
        {
            if( p == -1) { return; }
            Console.Write(" " + p);
            PreParse(nodes, nodes[p].left);
            PreParse(nodes, nodes[p].right);
        }
        private static void InParse(Node[] nodes, int p)
        {
            if( p == -1) { return; }
            InParse(nodes, nodes[p].left);
            Console.Write(" " + p);
            InParse(nodes, nodes[p].right);
        }
        private static void PostParse(Node[] nodes, int p)
        {
            if(p == -1) { return; }
            PostParse(nodes, nodes[p].left);
            PostParse(nodes, nodes[p].right);
            Console.Write(" " + p);
        }
    }

}



Measured memory_bytes: 9504