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

namespace ALDS1_7_C
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            Node[] nodeAry = new Node[n];

            for (int i = 0; i < n; i++)
            {
                nodeAry[i] = new Node();
            }

            for (int i = 0; i < n; i++)
            {
                int[] tmpLine = Console.ReadLine()
                                       .Split(' ')
                                       .Select(s => int.Parse(s))
                                       .ToArray();
                nodeAry[tmpLine[0]].val = tmpLine[0];

                if (tmpLine[1] >= 0)
                {
                    nodeAry[tmpLine[0]].leftSon = nodeAry[tmpLine[1]];
                    nodeAry[tmpLine[1]].parent = nodeAry[tmpLine[0]];
                }

                if (tmpLine[2] >= 0)
                {
                    nodeAry[tmpLine[0]].rightSon = nodeAry[tmpLine[2]];
                    nodeAry[tmpLine[2]].parent = nodeAry[tmpLine[0]];
                }
            }

            for (int i = 0; i < n; i++)
            {
                if (nodeAry[i].parent == null)
                {
                    StringBuilder preBuilder = new StringBuilder();
                    nodeAry[i].Preorder(preBuilder);
                    Console.WriteLine("Preorder");
                    Console.WriteLine(preBuilder.ToString());

                    StringBuilder inBuilder = new StringBuilder();
                    nodeAry[i].Inorder(inBuilder);
                    Console.WriteLine("Inorder");
                    Console.WriteLine(inBuilder.ToString());

                    StringBuilder postBuilder = new StringBuilder();
                    nodeAry[i].Postorder(postBuilder);
                    Console.WriteLine("Postorder");
                    Console.WriteLine(postBuilder.ToString());

                    break;
                }
            }
            
            //Console.ReadLine();
        }
    }

    class Node
    {
        public int val;
        public Node parent = null;
        public Node leftSon = null;
        public Node rightSon = null;

        public void Preorder(StringBuilder stringBuilder)
        {
            stringBuilder.Append(string.Format(" {0}", this.val));

            if (this.leftSon != null)
            {
                this.leftSon.Preorder(stringBuilder);
            }
            

            if (this.rightSon != null)
            {
                this.rightSon.Preorder(stringBuilder);
            }
        }

        public void Inorder(StringBuilder stringBuilder)
        {
            if (this.leftSon != null)
            {
                this.leftSon.Inorder(stringBuilder);
            }

            stringBuilder.Append(string.Format(" {0}", this.val));

            if (this.rightSon != null)
            {
                this.rightSon.Inorder(stringBuilder);
            }
        }

        public void Postorder(StringBuilder stringBuilder)
        {
            if (this.leftSon != null)
            {
                this.leftSon.Postorder(stringBuilder);
            }

            if (this.rightSon != null)
            {
                this.rightSon.Postorder(stringBuilder);
            }

            stringBuilder.Append(string.Format(" {0}", this.val));
        }
    }
}


Measured memory_bytes: 18416