import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;
import java.util.StringTokenizer;

public class Main {

	static class Node {
		int id, parentId, left, right;
		boolean visited;
		public Node(int id) {
			this.id = id;
			parentId = left = right = -1;
			visited = false;
		}
		public String toString() {return String.format("%d", id);}
	}

	public static void main(String[] args) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		Node[] nodes = new Node[n];
		for (int i = 0; i < n; i++) {
			StringTokenizer st = new StringTokenizer(reader.readLine());
			int id = Integer.parseInt(st.nextToken());
			int left = Integer.parseInt(st.nextToken());
			int right = Integer.parseInt(st.nextToken());
			if (nodes[id] == null) nodes[id] = new Node(id);
			nodes[id].left = left;
			nodes[id].right = right;
			if (left != -1) {
				if (nodes[left] == null) nodes[left] = new Node(left);
				nodes[left].parentId = id;
			}
			if (right != -1) {
				if (nodes[right] == null) nodes[right] = new Node(right);
				nodes[right].parentId = id;
			}
		}
		int rootId = -1;
		for (int i = 0; i < n; i++) {
			if (nodes[i].parentId == -1) {
				rootId = nodes[i].id;
				break;
			}
		}
		
		System.out.println("Preorder");
		preOrder(nodes, rootId);
		System.out.println("Inorder");
		inOrder(nodes, rootId);
		System.out.println("Postorder");
		postOrder(nodes, rootId);		
	}

	private static void resetVisitedFlag(Node[] nodes) {
		for (int i = 0; i < nodes.length; i++) {
			nodes[i].visited = false;
		}
	}
	
	private static void visit(Node node) {
		if (!node.visited) {
			System.out.print(" " + node);
			node.visited = true;		
		}
	}
	
	private static void preOrder(Node[] nodes, int rootId) {		
		Stack<Integer> stack = new Stack<Integer>();
		stack.push(rootId);
		while (!stack.isEmpty()) {
			Node node = nodes[stack.pop()];
			visit(node);
			if (node.right != -1) {
				stack.push(node.right);
			}
			if (node.left != -1) {
				stack.push(node.left);
			}
		}
		System.out.println("");	
		resetVisitedFlag(nodes);
	}
	
	private static void inOrder(Node[] nodes, int rootId) {
		Stack<Integer> stack = new Stack<Integer>();
		stack.push(rootId);
		while (!stack.isEmpty()) {
			Node node = nodes[stack.pop()];
			if (node.right != -1 && !nodes[node.right].visited) {
				stack.push(node.right);
			}
			if (node.left == -1 || nodes[node.left].visited) {
				visit(node);
			} else {
				stack.push(node.id);
			}
			if (node.left != -1 && !nodes[node.left].visited) {
				stack.push(node.left);
			}
		}
		System.out.println("");	
		resetVisitedFlag(nodes);
	}
	
	private static void postOrder(Node[] nodes, int rootId) {
		Stack<Integer> stack = new Stack<Integer>();
		stack.push(rootId);
		while (!stack.isEmpty()) {
			Node node = nodes[stack.pop()];
			if ((node.left == -1 || nodes[node.left].visited) && (node.right == -1 || nodes[node.right].visited)) {
				visit(node);
			} else {
				stack.push(node.id);
			}
			if (node.right != -1 && !nodes[node.right].visited) {
				stack.push(node.right);
			}
			if (node.left != -1 && !nodes[node.left].visited) {
				stack.push(node.left);
			}
		}
		System.out.println("");	
		resetVisitedFlag(nodes);
	}
}


Measured memory_bytes: 24548