using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
public class node
{
	public node parent;
	public node sibling;
	public node rightChild;
	public node leftChild;
	public int id;
	public int depth;
	public int height;
	public int degree;
	public bool isChecked = false;
 
	public override string ToString()
	{
		string result = "node ";
 
		result += id + ": parent = ";
		result += (depth == 0)?  "-1" : parent.id.ToString();
		result += ", sibling = ";
		result += (sibling != null)? sibling.id.ToString() : "-1";
		result += ", degree = " + degree;
		result += ", depth = " + depth;
		result += ", height = " + height + ", ";
 
		if(depth == 0){
			result += "root";
		} else if(degree == 0) {
			result += "leaf";
		} else {
			result += "internal node";
		}
 
		return result;
	}
 
}
 
public class Test
{
	public static int[] preorderId, inorderId, postorderId;
    public static int precount, incount, postcount;
 
	public static void Main()
	{
		int n = int.Parse(Console.ReadLine());
 
		node[] tree = new node[n];
		preorderId = new int[n];
		inorderId = new int[n];
		postorderId = new int[n];
 
		for(int i = 0; i < n; i++ ){
			int[] A = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
 
			if(tree[A[0]] == null) tree[A[0]]= new node();
			tree[A[0]].id = A[0];
 
			if(A[1] != -1) {
				if(tree[A[1]] == null) tree[A[1]]= new node();
				tree[A[1]].id = A[1];
				tree[A[1]].parent = tree[A[0]];
				tree[A[0]].leftChild = tree[A[1]];
				tree[A[0]].degree++;
 
				if(A[2] != -1) {
					if(tree[A[2]] == null) tree[A[2]] = new node();
					tree[A[1]].sibling = tree[A[2]];
				}
			}
 
			if(A[2] != -1) {
				if(tree[A[2]] == null) tree[A[2]]= new node();
				tree[A[2]].id = A[2];
				tree[A[2]].parent = tree[A[0]];
				tree[A[0]].rightChild = tree[A[2]];
				tree[A[0]].degree++;
 
				if(A[1] != -1) {
					tree[A[2]].sibling = tree[A[1]];
				}
			}
		}
 
		//oya sagasi
		node t = tree[0];
		while(t.parent != null) {
			t = t.parent;
		}
 
		Preorder(t, tree);
		Inorder(t, tree);
		Postorder(t, tree);
 
		Console.WriteLine("Preorder");
        for (int i = 0; i < n; i++)
        {
            Console.Write(" " + preorderId[i]);
        }
        Console.WriteLine();
        Console.WriteLine("Inorder");
        for (int i = 0; i < n; i++)
        {
            Console.Write(" " + inorderId[i]);
        }
        Console.WriteLine();
        Console.WriteLine("Postorder");
        for (int i = 0; i < n; i++)
        {
            Console.Write(" " + postorderId[i]);
        }
        Console.WriteLine();
	}
 
	public static void Preorder(node t, node[] tree)
	{
		preorderId[precount++] = t.id;
		if(t.leftChild != null) Preorder(t.leftChild, tree);
		if(t.rightChild != null) Preorder(t.rightChild, tree);
	}
 
	public static void Inorder(node t, node[] tree)
	{
		if(t.leftChild != null) Inorder(t.leftChild, tree);
		inorderId[incount++] = t.id;
		if(t.rightChild != null) Inorder(t.rightChild, tree);
	}
 
	public static void Postorder(node t, node[] tree)
	{
		if(t.leftChild != null) Postorder(t.leftChild, tree);
		if(t.rightChild != null) Postorder(t.rightChild, tree);
		postorderId[postcount++] = t.id;
	}
}

Measured memory_bytes: 9168