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

namespace ALDS1_7_C_TreeWalk
{
	class Program
	{
		static void Main ( string[] args )
		{
			//input
			int dataCount = int.Parse (Console.ReadLine ());

			BinaryTree binaryTree = new BinaryTree (dataCount);

			for (int lp = 0; lp < dataCount; lp++)
			{
				int[] inputNum = Console.ReadLine ().Split (' ').Select (int.Parse).ToArray ();
				binaryTree.Insert (inputNum[0], inputNum[1], inputNum[2]);
			}

			//process
			int index = 0;
			while (binaryTree.NodeArray[index].Parent != BinaryTree.Null)
			{
				index = binaryTree.NodeArray[index].Parent;
			}

			int parentNumber = index;

			//output
			#region
			Console.WriteLine ("Preorder");
			int[] preOrderResult = binaryTree.PreOrder (parentNumber);
			string preOrderOutput = string.Join (" ", Array.ConvertAll (preOrderResult, num => num.ToString ()));
			Console.WriteLine (" " + preOrderOutput);

			Console.WriteLine ("Inorder");
			int[] inOrderResult = binaryTree.InOrder (parentNumber);
			string inOrderOutput = string.Join (" ", Array.ConvertAll (inOrderResult, num => num.ToString ()));
			Console.WriteLine (" " + inOrderOutput);

			Console.WriteLine ("Postorder");
			int[] postOrderResult = binaryTree.PostOrder (parentNumber);
			string postOrderOutput = string.Join (" ", Array.ConvertAll (postOrderResult, num => num.ToString ()));
			Console.WriteLine (" " + postOrderOutput);
			#endregion
		}
	}

	class Node
	{
		public Node ()
		{
			this.Parent = BinaryTree.Null;
		}

		public int Parent { set; get; }
		public int Left { set; get; }
		public int Right { set; get; }
	}

	class BinaryTree
	{
		public BinaryTree ( int capacity )
		{
			this.NodeArray = new Node[capacity];

			for (int lp = 0; lp < NodeArray.Length; lp++)
			{
				NodeArray[lp] = new Node ();
			}
		}

		public Node[] NodeArray { private set; get; }
		public const int Null = -1;

		public void Insert ( int parent, int left, int right )
		{
			//???????¨????
			NodeArray[parent].Left = left;
			NodeArray[parent].Right = right;

			//???????¨????
			if (left != Null)
				NodeArray[left].Parent = parent;

			if (right != Null)
				NodeArray[right].Parent = parent;
		}

		//PreOrder
		public int[] PreOrder ( int parentNumber )
		{
			Queue<int> result = new Queue<int> (NodeArray.Length);
			PreOrder (parentNumber, result);
			return result.ToArray ();
		}
		//root->left->right
		private void PreOrder ( int nodeNumber, Queue<int> result )
		{
			if (nodeNumber != Null)
			{
				result.Enqueue (nodeNumber);

				PreOrder (NodeArray[nodeNumber].Left, result);
				PreOrder (NodeArray[nodeNumber].Right, result);
			}
		}

		//InOrder
		public int[] InOrder ( int parentNumber )
		{
			Queue<int> result = new Queue<int> (NodeArray.Length);
			InOrder (parentNumber, result);
			return result.ToArray ();
		}
		//left->toor->right
		private void InOrder ( int nodeNumber, Queue<int> result )
		{
			if (nodeNumber != Null)
			{
				InOrder (NodeArray[nodeNumber].Left, result);

				result.Enqueue (nodeNumber);

				InOrder (NodeArray[nodeNumber].Right, result);
			}
		}

		//PostOrder
		public int[] PostOrder ( int parentNumber )
		{
			Queue<int> result = new Queue<int> (NodeArray.Length);
			PostOrder (parentNumber, result);
			return result.ToArray ();
		}
		//left->right->root
		private void PostOrder ( int nodeNumber, Queue<int> result )
		{
			if (nodeNumber != Null)
			{
				PostOrder (NodeArray[nodeNumber].Left, result);
				PostOrder (NodeArray[nodeNumber].Right, result);

				result.Enqueue (nodeNumber);
			}
		}
	}
}

Measured memory_bytes: 10528