#include <stdio.h>

typedef struct {
	int left;
	int right;
	int par;
}data;

void preorder(data* T,int i) {
	printf(" %d", i);
	if(T[i].left!=-1) preorder(T,T[i].left);
	if(T[i].right!=-1) preorder(T,T[i].right);
}

void inorder(data* T, int i) {
	if (T[i].left != -1) inorder(T,T[i].left);
	printf(" %d", i);
	if(T[i].right!=-1) inorder(T,T[i].right);
}

void postorder(data* T, int i) {
	if (T[i].left != -1) postorder(T,T[i].left);
	if(T[i].right!=-1) postorder(T,T[i].right);
	printf(" %d", i);
}

int main() {
	int i,n;
	data T[25];
	int id, left, right;

	scanf("%d", &n);

	for (i = 0; i < n; i++) T[i].left = T[i].right = T[i].par = -1;


	for (i = 0; i < n; i++){
		scanf("%d%d%d", &id, &left, &right);
		if (left != -1) {
			T[id].left = left;
			T[left].par = id;
		}
		if (right != -1) {
			T[id].right = right;
			T[right].par = id;
		}
	}

	for (i = 0; i < n; i++)
		if (T[i].par == -1) break;

			printf("Preorder\n");
			preorder(T,i);
			printf("\n");

			printf("Inorder\n");
			inorder(T,i);
			printf("\n");

			printf("Postorder\n");
			postorder(T,i);
			printf("\n");


	return 0;
}

