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

namespace _20170410_AOJ_ALDS1_7B
{
    class ALDS1_7B
    {
        static void Main(string[] args)
        {
            for (;;)
            {
                string line = Console.ReadLine();
                if (string.IsNullOrEmpty(line))
                {
                    break;
                }

                int n = int.Parse(line);

                TreeNode[] arr = new TreeNode[n];
                for (int i = 0; i < n; i++)
                {
                    int[] nInfo = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

                    int id = nInfo[0];
                    TreeNode tn = arr[id];
                    if (tn == null)
                    {
                        tn = new TreeNode();
                        tn.Id = id;
                        arr[tn.Id] = tn;
                    }

                    int left = nInfo[1];
                    if (left >= 0)
                    {
                        TreeNode cn = arr[left];
                        if (cn == null)
                        {
                            cn = new TreeNode();
                            cn.Id = left;
                            arr[left] = cn;
                        }
                        tn.Left = cn;
                        cn.Parent = tn;
                    }

                    int right = nInfo[2];
                    if (right >= 0)
                    {
                        TreeNode cn = arr[right];
                        if (cn == null)
                        {
                            cn = new TreeNode();
                            cn.Id = right;
                            arr[right] = cn;
                        }
                        tn.Right = cn;
                        cn.Parent = tn;
                    }
                }

                TreeNode root = arr[0].GetRoot();
                root.SetDepthRecursive(0);

                /*
                foreach (var v in arr)
                {
                    WriteTreeNode(v);
                }
                */

                WriteOrder(root);
            }
        }

        static void WriteOrder(TreeNode tn)
        {
            List<TreeNode> list = new List<TreeNode>();
            Console.WriteLine("Preorder");
            PreOrder(list, tn);
            Console.Write(" ");
            Console.WriteLine(string.Join(" ", list.Select(x => x.Id.ToString()).ToArray()));

            list = new List<TreeNode>();
            Console.WriteLine("Inorder");
            InOrder(list, tn);
            Console.Write(" ");
            Console.WriteLine(string.Join(" ", list.Select(x => x.Id.ToString()).ToArray()));

            list = new List<TreeNode>();
            Console.WriteLine("Postorder");
            PostOrder(list, tn);
            Console.Write(" ");
            Console.WriteLine(string.Join(" ", list.Select(x => x.Id.ToString()).ToArray()));
        }

        static void PreOrder(List<TreeNode> list, TreeNode tn)
        {
            list.Add(tn);

            if (tn.Left != null)
            {
                PreOrder(list, tn.Left);
            }
            
            if(tn.Right != null)
            {
                PreOrder(list, tn.Right);
            }
        }

        static void InOrder(List<TreeNode> list, TreeNode tn)
        {
            if (tn.Left != null)
            {
                InOrder(list, tn.Left);
            }

            list.Add(tn);

            if (tn.Right != null)
            {
                InOrder(list, tn.Right);
            }
        }

        static void PostOrder(List<TreeNode> list, TreeNode tn)
        {
            if (tn.Left != null)
            {
                PostOrder(list, tn.Left);
            }

            if (tn.Right != null)
            {
                PostOrder(list, tn.Right);
            }

            list.Add(tn);
        }

        static void WriteTreeNode(TreeNode tn)
        {
            int parent = (tn.Parent == null) ? -1 : tn.Parent.Id;
            TreeNode sibling = tn.Sibling();
            int ssib = (sibling == null) ? -1 : sibling.Id;
            int degree = tn.Degree();
            Console.Write(
                "node {0}: parent = {1}, sibling = {2}, degree = {3}, depth = {4}, height = {5}, ",
                tn.Id,
                parent,
                ssib,
                degree,
                tn.Depth,
                tn.Height);
            if (parent < 0)
            {
                Console.WriteLine("root");
            }
            else
            {
                if (degree > 0)
                {
                    Console.WriteLine("internal node");
                }
                else
                {
                    Console.WriteLine("leaf");
                }
            }
        }
    }

    class TreeNode
    {
        public int Id { get; set; }
        public TreeNode Parent { get; set; }
        public TreeNode Left { get; set; }
        public TreeNode Right { get; set; }
        public int Depth { get; internal set; }
        public int Height { get; internal set; }
        public TreeNode()
        {
        }

        public int Degree()
        {
            int d = 0;
            if (Left != null)
            {
                d++;
            }
            if (Right != null)
            {
                d++;
            }
            return d;
        }

        public TreeNode Sibling()
        {
            TreeNode sibling = null;
            if (Parent != null)
            {
                if (Parent.Left == this)
                {
                    sibling = Parent.Right;
                }
                else
                {
                    sibling = Parent.Left;
                }
            }

            return sibling;
        }

        public void SetDepth()
        {
            int d = 0;
            TreeNode temp = this;
            do
            {
                temp = temp.Parent;
                d++;
            } while (temp != null);

            Depth = d;
        }

        public TreeNode GetRoot()
        {
            TreeNode temp = this;
            while (temp.Parent != null)
            {
                temp = temp.Parent;
            }

            return temp;
        }

        public void SetDepthRecursive(int depth)
        {
            Depth = depth;
            int lh = 0;
            if (Left != null)
            {
                Left.SetDepthRecursive(depth + 1);
                lh = Left.Height + 1;
            }

            int rh = 0;
            if (Right != null)
            {
                Right.SetDepthRecursive(depth + 1);
                rh = Right.Height + 1;
            }

            Height = Math.Max(lh, rh);
        }
    }
}



Measured memory_bytes: 9608