#include <stdio.h>
#define max(x,y) ((x>y)?x:y)

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

node_t node[100];
int n;

int getRoot();
void printPreorder(int);
void printInorder(int);
void printPostorder(int);
int getSibling(int);


int main() {
	int i;
	int ID, left, right;
	scanf("%d", &n);
	for (i = 0; i < n; i++) node[i].left = node[i].right = node[i].parent = -1;
	for (i = 0; i < n; i++) {
		scanf("%d %d %d", &ID, &left, &right);
		node[ID].left = left;
		node[ID].right = right;

		if (left != -1) node[left].parent = ID;
		if (right != -1) node[right].parent = ID;
	}
	int root = getRoot();
	printf("Preorder\n");
	printPreorder(root);
	printf("\n");
	printf("Inorder\n");
	printInorder(root);
	printf("\n");
	printf("Postorder\n");
	printPostorder(root);
	printf("\n");
	return 0;
}

int getRoot(){
    int i;
    for (i = 0; i < n; i++) if (node[i].parent == -1) break;
    return i;
}

void printPreorder(int x){
    if (x != -1) {
		printf(" %d", x);
		printPreorder(node[x].left);
		printPreorder(node[x].right);
	}
}

void printInorder(int x){
    if (x != -1) {
		printInorder(node[x].left);
		printf(" %d", x);
		printInorder(node[x].right);
	}
}

void printPostorder(int x){
    if (x != -1) {
		printPostorder(node[x].left);
		printPostorder(node[x].right);
		printf(" %d", x);
	}
}


int getSibling(int ID) {
	if (node[ID].parent != -1 && node[node[ID].parent].right != ID) return node[node[ID].parent].right;
	if (node[ID].parent != -1 && node[node[ID].parent].left != ID) return node[node[ID].parent].left;
	return -1;
}

