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

class Program
{

    public void Proc()
    {
        int nodeCount = int.Parse(Console.ReadLine());
        Dictionary<int, TreeNd> dic = new Dictionary<int, TreeNd>();
        List<TreeNd> list = new List<TreeNd>();
        for (int i = 0; i < nodeCount; i++)
        {
            string[] inpt = Console.ReadLine().Split(' ');

            int nodeId = int.Parse(inpt[0]);
            int subLeftId = int.Parse(inpt[1]);
            int subRightId = int.Parse(inpt[2]);

            TreeNd nd = null;
            if (dic.ContainsKey(nodeId))
            {
                nd = dic[nodeId];
            }
            else
            {
                nd = new TreeNd(nodeId);
                dic.Add(nodeId, nd);
                list.Add(nd);
            }
            if (subLeftId >= 0)
            {
                TreeNd subnode = null;
                if (dic.ContainsKey(subLeftId))
                {
                    subnode = dic[subLeftId];
                }
                else
                {
                    subnode = new TreeNd(subLeftId);
                    dic.Add(subLeftId, subnode);
                    list.Add(subnode);
                }
                subnode.Parent = nd;
                nd.SubLeft = subnode;
            }
            if (subRightId >= 0)
            {
                TreeNd subnode = null;
                if (dic.ContainsKey(subRightId))
                {
                    subnode = dic[subRightId];
                }
                else
                {
                    subnode = new TreeNd(subRightId);
                    dic.Add(subRightId, subnode);
                    list.Add(subnode);
                }
                subnode.Parent = nd;
                nd.SubRight = subnode;
            }
        }
        // root ??¢???
        TreeNd root = null;
        foreach (TreeNd trg in list)
        {
            if (trg.Parent == null)
            {
                root = trg;
                break;
            }
        }
        if (root == null)
        {
            Console.WriteLine("err");
        }
        this.Output(root);
        Console.WriteLine("Preorder");
        Console.WriteLine(this.PreOrder.ToString());
        Console.WriteLine("Inorder");
        Console.WriteLine(this.InOrder.ToString());
        Console.WriteLine("Postorder");
        Console.WriteLine(this.PostOrder.ToString());
    }

    private StringBuilder PreOrder = new StringBuilder();
    private StringBuilder InOrder = new StringBuilder();
    private StringBuilder PostOrder = new StringBuilder();
    private void Output(TreeNd parent)
    {
        PreOrder.Append(" " + parent.NodeId);
        if (parent.SubLeft != null)
        {
            this.Output(parent.SubLeft);
        }
        InOrder.Append(" " + parent.NodeId);
        if (parent.SubRight != null)
        {
            this.Output(parent.SubRight);
        }
        PostOrder.Append(" " + parent.NodeId);
    }

    public class TreeNd
    {
        public int NodeId = -1;
        public TreeNd Parent = null;

        public TreeNd(int id)
        {
            this.NodeId = id;
        }

        public TreeNd SubLeft = null;
        public TreeNd SubRight = null;

    }

    static void Main(string[] args)
    {
        Program prg = new Program();
        prg.Proc();
    }
}

Measured memory_bytes: 9772