#include <stdio.h>

#define NIL -1
#define PARENT 0
#define LEFT 1
#define RIGHT 2

int Tree[25][3];

void Preorder(int pos) {
	if (pos == NIL) return;
	printf(" %d", pos);
	Preorder(Tree[pos][LEFT]);
	Preorder(Tree[pos][RIGHT]);
}

void Inorder(int pos) {
	if (pos == NIL) return;
	Inorder(Tree[pos][LEFT]);
	printf(" %d", pos);
	Inorder(Tree[pos][RIGHT]);
}

void Postorder(int pos) {
	if (pos == NIL) return;
	Postorder(Tree[pos][LEFT]);
	Postorder(Tree[pos][RIGHT]);
	printf(" %d", pos);
}

int main() {
	int i, n, pos, left, right;

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

	for (i = 0; i < n; i++) {
		scanf("%d %d %d", &pos, &left, &right);
		Tree[pos][LEFT] = left;
		Tree[pos][RIGHT] = right;
		if (left != NIL) Tree[left][PARENT] = pos;
		if (right != NIL) Tree[right][PARENT] = pos;
	}

	i = 0;
	while (Tree[i][PARENT] != NIL) i++;

	printf("Preorder\n");
	Preorder(i);
	printf("\n");

	printf("Inorder\n");
	Inorder(i);
	printf("\n");

	printf("Postorder\n");
	Postorder(i);
	printf("\n");

	return 0;
}

