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

/*
 */

public class ALDS1_7_C
{
    private struct Node
    {
        public int NodeId;
        public int ParentId;
        public int SiblingId;
        public int LeftId;
        public int RightId;

        public Node(int nodeId)
        {
            NodeId = nodeId;
            ParentId = -1;
            LeftId = -1;
            RightId = -1;
            SiblingId = -1;
        }
    }

    public static void Main(string[] args)
    {
        //var exStdIn = new System.IO.StreamReader( "input.txt" );
        //System.Console.SetIn( exStdIn );

        int n = int.Parse(Console.ReadLine());
        Node[] nodes = new Node[n];
        for (int i = 0; i < n; i++)
        {
            nodes[i] = new Node(i);
        }

        for (int i = 0; i < n; i++)
        {
            string[] str = Console.ReadLine().Split(' ');
            int index = int.Parse(str[0]);
            int leftId = int.Parse(str[1]);
            int rightId = int.Parse(str[2]);
            if (leftId != -1)
            {
                nodes[index].LeftId = leftId;
                nodes[leftId].ParentId = index;
                nodes[leftId].SiblingId = rightId;
            }
            if (rightId != -1)
            {
                nodes[index].RightId = rightId;
                nodes[rightId].ParentId = index;
                nodes[rightId].SiblingId = leftId;
            }
        }

        int rootId = -1;
        for (int i = 0; i < n; i++)
        {
            if (nodes[i].ParentId == -1)
            {
                rootId = i;
                break;
            }
        }

        StringBuilder sb = new StringBuilder();
        sb.Append("Preorder");
        sb.AppendLine();
        Preorder(nodes, sb, rootId);
        sb.AppendLine();
        sb.Append("Inorder");
        sb.AppendLine();
        Inorder(nodes, sb, rootId);
        sb.AppendLine();
        sb.Append("Postorder");
        sb.AppendLine();
        Postorder(nodes, sb, rootId);
        Console.WriteLine(sb.ToString());
    }

    private static void Preorder(Node[] nodes, StringBuilder sb, int index)
    {
        sb.AppendFormat(" {0}", index.ToString());
        if (nodes[index].LeftId != -1)
        {
            Preorder(nodes, sb, nodes[index].LeftId);
        }
        if (nodes[index].RightId != -1)
        {
            Preorder(nodes, sb, nodes[index].RightId);
        }
    }

    private static void Inorder(Node[] nodes, StringBuilder sb, int index)
    {
        if (nodes[index].LeftId != -1)
        {
            Inorder(nodes, sb, nodes[index].LeftId);
        }
        sb.AppendFormat(" {0}", index.ToString());
        if (nodes[index].RightId != -1)
        {
            Inorder(nodes, sb, nodes[index].RightId);
        }
    }

    private static void Postorder(Node[] nodes, StringBuilder sb, int index)
    {
        if (nodes[index].LeftId != -1)
        {
            Postorder(nodes, sb, nodes[index].LeftId);
        }
        if (nodes[index].RightId != -1)
        {
            Postorder(nodes, sb, nodes[index].RightId);
        }
        sb.AppendFormat(" {0}", index.ToString());
    }
}



Measured memory_bytes: 15984