#include <stdio.h>

#define MAX 30
#define NIL -1

struct Node {
	int parent;
	int left;
	int right;
};

void preorder(struct Node *tree, int cur) {
	if (cur == NIL) return;
	printf(" %d", cur);
	preorder(tree, tree[cur].left);
	preorder(tree, tree[cur].right);
}

void inorder(struct Node *tree, int cur) {
	if (cur == NIL) return;
	inorder(tree, tree[cur].left);
	printf(" %d", cur);
	inorder(tree, tree[cur].right);
}

void postorder(struct Node *tree, int cur) {
	if (cur == NIL) return;
	postorder(tree, tree[cur].left);
	postorder(tree, tree[cur].right);
	printf(" %d", cur);
}

int main() {
	int i, n, id, left, right, root;
	struct Node tree[MAX];

	scanf("%d", &n);
	for (i = 0; i < n; i++) tree[i].parent = NIL;

	for (i = 0; i < n; i++) {
		scanf("%d %d %d", &id, &left, &right);
		tree[id].left = left;
		tree[id].right = right;
		if (left != NIL) tree[left].parent = id;
		if (right != NIL) tree[right].parent = id;
	}

	for (i = 0; i < n; i++) {
		if (tree[i].parent == NIL) {
			root = i;
			break;
		}
	}

	printf("Preorder\n");
	preorder(tree, root);
	printf("\n");
	printf("Inorder\n");
	inorder(tree, root);
	printf("\n");
	printf("Postorder\n");
	postorder(tree, root);
	printf("\n");

	return 0;
}
