/* ALDS1_7_C:TreeWalk */
/* 20181125 AOJ */

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#define N 25
#define NIL -1

typedef struct {
	int parent;
	int left;
	int right;
} Tree;

void Preorder(Tree *node, int id);
void Inorder(Tree *node, int id);
void Postorder(Tree *node, int id);

int main(void) {
	Tree *node = (Tree *)malloc(sizeof(Tree) * N);
	int i, n, id, left, right, root;

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

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

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

	printf("Preorder\n");
	Preorder(node, root);
	printf("\n");
	printf("Inorder\n");
	Inorder(node, root);
	printf("\n");
	printf("Postorder\n");
	Postorder(node, root);
	printf("\n");

	return 0;
}


void Preorder(Tree *node, int id) {
	if(id == NIL) return;
	printf(" %d", id);
	Preorder(node, node[id].left);
	Preorder(node, node[id].right);
}

void Inorder(Tree *node, int id) {
	if(id == NIL) return;
	Inorder(node, node[id].left);
	printf(" %d", id);
    Inorder(node, node[id].right);
}

void Postorder(Tree *node, int id) {
	if(id == NIL) return;
	Postorder(node, node[id].left);
    Postorder(node, node[id].right);
	printf(" %d", id);
}
