#include <stdio.h>
#define MAX 100005
#define NIL -1

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

struct Node Tree[MAX];
int n;

void preParse(int u) {
	if ( u == NIL ) return;
	printf(" %d",u);
	preParse(Tree[u].left);
	preParse(Tree[u].right);
}
void inParse(int u) {
	if ( u == NIL ) return;
	inParse(Tree[u].left);
	printf(" %d",u);
	inParse(Tree[u].right);
}

void postParse(int u) {
	if ( u == NIL ) return;
	postParse(Tree[u].left);
	postParse(Tree[u].right);
	printf(" %d",u);
}

int main () {
	int i, v, l, r, root;

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

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

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

	printf("Preorder\n");
	preParse(root);
	printf("\nInorder\n");
	inParse(root);
	printf("\nPostorder\n");
	postParse(root);
	printf("\n");

    return 0;
}
