#include <stdio.h>
#include <stdlib.h>


typedef struct tree_t{
	int parent;
	int left;
	int right;
} TREE_T;

TREE_T *TREE;


int n;
int COUNT;

void Preorder(int soeji)
{
	printf(" %d", soeji);
	COUNT++;
	if(n == COUNT){
		printf("\n");
		return;
	}

	if(TREE[soeji].left != -1)
		Preorder(TREE[soeji].left);

	if(TREE[soeji].right != -1)
	Preorder(TREE[soeji].right);
}


void Inorder(int soeji)
{
	if(TREE[soeji].left != -1)
		Inorder(TREE[soeji].left);

	printf(" %d", soeji);
	COUNT++;
	if(n == COUNT){
		printf("\n");
		return;
	}

	if(TREE[soeji].right != -1)
		Inorder(TREE[soeji].right);
}


void Postorder(int soeji)
{
	if(TREE[soeji].left != -1)
		Postorder(TREE[soeji].left);

	if(TREE[soeji].right != -1)
		Postorder(TREE[soeji].right);

	printf(" %d", soeji);
	COUNT++;
	if(n == COUNT){
		printf("\n");
		return;
	}
}


int main()
{
	int id;
	int left, right;
	int root;
	int i;

	scanf("%d", &n);

	TREE = (TREE_T *)malloc(sizeof(TREE_T) * n);

	for(i = 0; i < n; i++)
		TREE[i].parent = -1;

	for(i = 0; i < n; i++){
		scanf("%d %d %d", &id, &left, &right);
		TREE[id].left = left;
		TREE[id].right = right;

		TREE[left].parent = id;
		TREE[right].parent = id;
	}

	// 根の番号を求める
	i = -1;
	while(TREE[++i].parent != -1);
	root = i;

	// 表示
	COUNT = 0;
	printf("Preorder\n");
	Preorder(root);

	COUNT = 0;
	printf("Inorder\n");
	Inorder(root);

	COUNT = 0;
	printf("Postorder\n");
	Postorder(root);

	return 0;
}
