#include<stdio.h>
#define MAX 30

struct NODE { int parent, left, right; };

struct NODE Tree[MAX];

void Preorder(int N, int id) {
	printf(" %d", id);
	if (Tree[id].left != -1)Preorder(N, Tree[id].left);
	if (Tree[id].right != -1)Preorder(N, Tree[id].right);
}

void Inorder(int N, int id) {
	if (Tree[id].left != -1)Inorder(N, Tree[id].left);
	printf(" %d", id);
	if (Tree[id].right != -1)Inorder(N, Tree[id].right);
}

void Postorder(int N, int id) {
	if (Tree[id].left != -1)Postorder(N, Tree[id].left);
	if (Tree[id].right != -1)Postorder(N, Tree[id].right);
	printf(" %d", id);
}

int main() {
	int N;
	int id, l, r;
	int root;
	for (int i = 0; i < 30; i++) {
		Tree[i].parent = -1; Tree[i].left = -1; Tree[i].right = -1;
	}
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d %d %d", &id, &l, &r);
		if (l != -1) {
			Tree[id].left = l;
			Tree[l].parent = id;
		}
		if (r != -1) {
			Tree[id].right = r;
			Tree[r].parent = id;
		}
	}
	for (int i = 0; i < N; i++) {
		if (Tree[i].parent == -1) {
			root = i;
			break;
		}
	}
	printf("Preorder\n");
	Preorder(N, root); printf("\n");
	printf("Inorder\n");
	Inorder(N, root); printf("\n");
	printf("Postorder\n");
	Postorder(N, root); printf("\n");
	return 0;
}
