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

namespace ALDS1_7_C
{
    public class Program

    {
        public static void Main(string[] args)
        {
            int n = ReadInt();
            BinaryTree<int> bt = new BinaryTree<int>();
            NodeList<int> nodes = new NodeList<int>();
            for (int i = 0 ; i < n ; i++)
            {
                int[] line = ReadIntAr();
                if (nodes.FindByValue(line[0]) == null) nodes.Add(new BinaryTreeNode<int>(line[0]));
                if (line[1] != -1 && nodes.FindByValue(line[1]) == null) nodes.Add(new BinaryTreeNode<int>(line[1]));
                if (line[2] != -1 && nodes.FindByValue(line[2]) == null) nodes.Add(new BinaryTreeNode<int>(line[2]));
                ((BinaryTreeNode<int>)nodes.FindByValue(line[0])).Left = (BinaryTreeNode<int>)nodes.FindByValue(line[1]);
                if (line[1] != -1) ((BinaryTreeNode<int>)nodes.FindByValue(line[1])).Parent = (BinaryTreeNode<int>)nodes.FindByValue(line[0]);
                ((BinaryTreeNode<int>)nodes.FindByValue(line[0])).Right = (BinaryTreeNode<int>)nodes.FindByValue(line[2]);
                if (line[2] != -1) ((BinaryTreeNode<int>)nodes.FindByValue(line[2])).Parent = (BinaryTreeNode<int>)nodes.FindByValue(line[0]);

            }

            BinaryTreeNode<int> tmp = (BinaryTreeNode<int>)nodes[0];
            while (true)
            {
                if (tmp.Parent == null)
                {
                    bt.Root = tmp;
                    break;
                }
                tmp = tmp.Parent;
            }

            List<int> res1 = new List<int>();
            List<int> res2 = new List<int>();
            List<int> res3 = new List<int>();
            bt.PreorderTraversal(bt.Root, res1);
            bt.InorderTraversal(bt.Root, res2);
            bt.PostorderTraversal(bt.Root, res3);

            Console.WriteLine("Preorder");
            Console.WriteLine(" {0}", string.Join(" ", res1.Select(x => x.ToString()).ToArray()));
            Console.WriteLine("Inorder");
            Console.WriteLine(" {0}", string.Join(" ", res2.Select(x => x.ToString()).ToArray()));
            Console.WriteLine("Postorder");
            Console.WriteLine(" {0}", string.Join(" ", res3.Select(x => x.ToString()).ToArray()));

        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }

    }
    
    public class Node<T>
    {
        private T data;
        private NodeList<T> neighbors = null;

        public Node() { }
        public Node(T data) : this(data, null) { }
        public Node(T data, NodeList<T> neighbors)
        {
            this.data = data;
            this.neighbors = neighbors;
        }

        public T Value { get { return data; } set { data = value; } }
        protected NodeList<T> Neighbors { get { return neighbors; } set { neighbors = value; } }

    }

    public class NodeList<T> : List<Node<T>>
    {
        public NodeList() : base() { }
        public NodeList(int initialSize)
        { for (int i = 0 ; i < initialSize ; i++) Add(default(Node<T>)); }

        public Node<T> FindByValue(T value)
        {
            foreach (Node<T> node in this) if (node.Value.Equals(value)) return node;
            return null;
        }
    }

    public class BinaryTreeNode<T> : Node<T>
    {
        public BinaryTreeNode() : base() { }
        public BinaryTreeNode(T data) : base(data, null) { }
        public BinaryTreeNode(T data, BinaryTreeNode<T> left, BinaryTreeNode<T> right)
        {
            base.Value = data;
            NodeList<T> children = new NodeList<T>(2);
            children[0] = left;
            children[1] = right;
            base.Neighbors = children;
        }

        public BinaryTreeNode<T> Parent { get; set; }

        public BinaryTreeNode<T> Left
        {
            get
            {
                if (base.Neighbors == null) return null;
                else return (BinaryTreeNode<T>)base.Neighbors[0];
            }
            set
            {
                if (base.Neighbors == null) base.Neighbors = new NodeList<T>(2);
                base.Neighbors[0] = value;
            }
        }

        public BinaryTreeNode<T> Right
        {
            get
            {
                if (base.Neighbors == null) return null;
                else return (BinaryTreeNode<T>)base.Neighbors[1];
            }
            set
            {
                if (base.Neighbors == null) base.Neighbors = new NodeList<T>(2);
                base.Neighbors[1] = value;
            }
        }
    }

    public class BinaryTree<T>
    {

        private BinaryTreeNode<T> root;

        public BinaryTree() { root = null; }
        public virtual void Clear() { root = null; }

        public BinaryTreeNode<T> Root
        {get { return root; } set { root = value; } }

        public void PreorderTraversal(BinaryTreeNode<T> current,List<T> res)
        {
            if (current != null)
            {
                res.Add(current.Value);
                PreorderTraversal(current.Left, res);
                PreorderTraversal(current.Right,res);
            }
        }

        public void InorderTraversal(BinaryTreeNode<T> current, List<T> res)
        {
            if (current != null)
            {
                InorderTraversal(current.Left, res);
                res.Add(current.Value);
                InorderTraversal(current.Right, res);
            }
        }

        public void PostorderTraversal(BinaryTreeNode<T> current, List<T> res)
        {
            if (current != null)
            {
                PostorderTraversal(current.Left, res);
                PostorderTraversal(current.Right, res);
                res.Add(current.Value);
            }
        }

        public virtual void Add(T data)
        {
            // create a new Node instance
            BinaryTreeNode<T> n = new BinaryTreeNode<T>(data);
            int result;
            Comparer comparer = new Comparer(System.Globalization.CultureInfo.CurrentCulture);

            // now, insert n into the tree
            // trace down the tree until we hit a NULL
            BinaryTreeNode<T> current = root, parent = null;
            while (current != null)
            {
                result = comparer.Compare(current.Value, data);
                if (result == 0)
                    // they are equal - attempting to enter a duplicate - do nothing
                    return;
                else if (result > 0)
                {
                    // current.Value > data, must add n to current's left subtree
                    parent = current;
                    current = current.Left;
                }
                else if (result < 0)
                {
                    // current.Value < data, must add n to current's right subtree
                    parent = current;
                    current = current.Right;
                }
            }

            if (parent == null)
                // the tree was empty, make n the root
                root = n;
            else
            {
                result = comparer.Compare(parent.Value, data);
                if (result > 0)
                    // parent.Value > data, therefore n must be added to the left subtree
                    parent.Left = n;
                else
                    // parent.Value < data, therefore n must be added to the right subtree
                    parent.Right = n;
            }
        }
    }

}



Measured memory_bytes: 16520