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

struct node {
	int parent;
	int child[2];
	int depth;
	int brother;
};

struct node tree[100000];

int getRoot(int num){
	if(tree[num].parent == -1){
		return num;
	}
	return getRoot(tree[num].parent);
}

void calcDepth(int num){
	int i;
	for(i=0;i<2;i++){
		if(tree[num].child[i] == -1){
			continue;
		}
		tree[tree[num].child[i]].depth = tree[num].depth + 1;
		calcDepth(tree[num].child[i]);
	}
	return;
}
/*
int calcHeight(int num){
	int i;
	int temp;
	int h = -1;
	if(num==-1){
		return -1;
	}
	for(i=0;i<2;i++){
		temp = calcHeight(tree[num].child[i]);
		h = (h>temp?h:temp);
	}
	tree[num].height = h + 1;
	return tree[num].height;
}
*/
void Preorder(int num){
	printf(" %d",num);
	if(tree[num].child[0]==-1){
		if(tree[num].child[1]==-1){
			return;
		}else{
			Preorder(tree[num].child[1]);
		}
	}
	Preorder(tree[num].child[0]);
	if(tree[num].child[1]==-1){
		return;
	}
	Preorder(tree[num].child[1]);
}

void Inorder(int num){
	if(tree[num].child[0]==-1&&tree[num].child[1]==-1){
		printf(" %d",num);
		return;
	}else if(tree[num].child[0]==-1&&tree[num].child[1]!=-1){
		printf(" %d",num);
		Inorder(tree[num].child[1]);
	}else if(tree[num].child[0]!=-1&&tree[num].child[1]==-1){
		Inorder(tree[num].child[0]);
		printf(" %d",num);
	}else{
		Inorder(tree[num].child[0]);
		printf(" %d",num);
		Inorder(tree[num].child[1]);
	}
	return;
}

int Postorder(int num){
	if(tree[num].child[0]==-1&&tree[num].child[1]==-1){
		printf(" %d",num);
		return;
	}else if(tree[num].child[0]==-1&&tree[num].child[1]!=-1){
		Postorder(tree[num].child[1]);
	}else if(tree[num].child[0]!=-1&&tree[num].child[1]==-1){
		Postorder(tree[num].child[0]);
	}else{
		Postorder(tree[num].child[0]);
		Postorder(tree[num].child[1]);
		printf(" %d",num);
	}
}

int main(){
	int n;
	int nodenum;
	int l;
	int r;
	int root;
	int i,j;
	scanf("%d",&n);

	for(i=0;i<n;i++){
		tree[i].parent = -1;
		tree[i].brother = -1;
	}

	for(i=0;i<n;i++){
		scanf("%d",&nodenum);
		scanf("%d %d",&l,&r);
		tree[nodenum].child[0] = l;
		tree[nodenum].child[1] = r;
		if(l != -1){
			tree[l].parent = nodenum;
			tree[l].brother = r;	
		}
		if(r != -1){
			tree[r].parent = nodenum;
			tree[r].brother = l;
		}
	}

	root = getRoot(0);

	tree[root].depth = 0;
	calcDepth(root);

	printf("Preorder\n");
	Preorder(root);
	printf("\n");
	printf("Inorder\n");
	Inorder(root);
	printf("\n");
	printf("Postorder\n");
	Postorder(root);
	printf("\n");
	return 0;
}