class TreeNode
{
	TreeNode left_  = null;
	TreeNode right_ = null;
	public TreeNode left{
		get { return left_;   }
	}
	public TreeNode right{
		get { return right_;   }
	}
	
	public void setLeftNode  (ref TreeNode node) { left_  = node; }
	public void setRightNode (ref TreeNode node) { right_ = node; }
	
	int key_;
	public int key {
		get { return key_;  }
	}
	public TreeNode (int i) { key_ = i;}
};

class InputInfo
{
	int id_      = 0;
	int leftId_  = 0;
	int rightId_ = 0;
	
	public int id {
		get { return id_; }
	}
	public int leftId {
		get { return leftId_; }
	}
	public int rightId {
		get { return rightId_; }
	}
	
	public static InputInfo parseInput()
	{
		string   inputStr = System.Console.ReadLine();
		string[] splitStr = inputStr.Split(' ');
		
		int[] input = new int[splitStr.Length];
		for(int i = 0; i < splitStr.Length; ++i) {
			input[i] = int.Parse(splitStr[i]);
		}
		InputInfo ret = new InputInfo(input);
		return ret;
	}
	
	public InputInfo(int[] input)
	{
		if (input.Length != 3) {
			System.Console.WriteLine("input: ??? WrongFormat");
			return;
		}
		id_      = input[0];
		leftId_  = input[1];
		rightId_ = input[2];
	}
};
interface ITraverser {
	bool run(TreeNode start, bool rec = false);
};
class PreOrderTraverser : ITraverser {
	int[] visitedNodeHist;
	int count = 0;
	public bool run(TreeNode visitedNode, bool rec = false) {
		bool ret = false;
		if (visitedNode != null) {
			visitedNodeHist[count++] = visitedNode.key;
			run(visitedNode.left, true);
			run(visitedNode.right, true);
		}
		if (rec == false) {
			if (count == visitedNodeHist.Length) { // ??¨??¢?´¢??§????????????
				for (int i = 0; i < visitedNodeHist.Length; ++i) {
					System.Console.Write(" {0}", visitedNodeHist[i]);
				}
				ret = true;
			}
			count = 0;
		}
		return ret;
	}
	public PreOrderTraverser(int i) {visitedNodeHist = new int[i];}
};
class InOrderTraverser : ITraverser {
	int[] visitedNodeHist;
	int count = 0;
	public bool run(TreeNode visitedNode, bool rec = false) {
		bool ret = false;
		if (visitedNode != null) {
			run(visitedNode.left, true);
			visitedNodeHist[count++] = visitedNode.key;
			run(visitedNode.right, true);
		}
		if (rec == false) {
			if (count == visitedNodeHist.Length) { // ??¨??¢?´¢??§????????????
				for (int i = 0; i < visitedNodeHist.Length; ++i) {
					System.Console.Write(" {0}", visitedNodeHist[i]);
				}
				ret = true;
			}
			count = 0;
		}
		return ret;
	}
	public InOrderTraverser(int i) {visitedNodeHist = new int[i];}
};
class PostOrderTraverser : ITraverser {
	int[] visitedNodeHist;
	int count = 0;
	public bool run(TreeNode visitedNode, bool rec = false) {
		bool ret = false;
		if (visitedNode != null) {
			run(visitedNode.left, true);
			run(visitedNode.right, true);
			visitedNodeHist[count++] = visitedNode.key;
		}
		if (rec == false) {
			if (count == visitedNodeHist.Length) { // ??¨??¢?´¢??§????????????
				for (int i = 0; i < visitedNodeHist.Length; ++i) {
					System.Console.Write(" {0}", visitedNodeHist[i]);
				}
				ret = true;
			}
			count = 0;
		}
		return ret;
	}
	public PostOrderTraverser(int i) {visitedNodeHist = new int[i];}
};

class Tree
{
	public static void Main()
	{
		int inputNum = int.Parse(System.Console.ReadLine());
		
		TreeNode[] tn = new TreeNode[inputNum]; // ???????????????
		for (int i = 0; i < inputNum; ++i) {
			tn[i] = new TreeNode(i);
		}
		
		//??\?¶?
		for (int i = 0; i < inputNum; ++i) {
			InputInfo input = InputInfo.parseInput();
			if (input.leftId  >= 0) tn[input.id].setLeftNode (ref tn[input.leftId ]);
			if (input.rightId >= 0) tn[input.id].setRightNode(ref tn[input.rightId]);
		}
		
		int root = 0;
		System.Console.WriteLine("Preorder");
		ITraverser prOT = new PreOrderTraverser(inputNum);
		while (prOT.run(tn[root]) != true) ++root; //?????¢???
		System.Console.WriteLine("");
		
		System.Console.WriteLine("Inorder");
		ITraverser inOT = new InOrderTraverser(inputNum);
		inOT.run(tn[root]);
		System.Console.WriteLine("");
		
		System.Console.WriteLine("Postorder");
		ITraverser poOT = new PostOrderTraverser(inputNum);
		poOT.run(tn[root]);
		System.Console.WriteLine("");
	}
}

Measured memory_bytes: 9084