#include <stdio.h>
#define MAX 100005;
#define NO -1;
typedef struct{
	int p;
	int l;
	int r;
}Tree;

Tree tree[MAX];
int count=0;
void pre(int);
void in(int);
void pos(int);

int main(void){
	int n;
	int i;
	int start;

	for(i=0;i<n;i++){
		tree[i].p=tree[i].l=&tree[i].r=NO;
	}

	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d%d",&tree[i].l,&tree[i].r);
		if(tree[i].l != NO) tree[tree[i].l].p=i;
		if(tree[i].l != NO) tree[tree[i].r].p=i;
	}
	for(i=0;i<n;i++){
		if(tree[i].p==NO) start = i;
	}	

	printf("Preorder\n");
	pre(start);
	printf("\n");
	count=0;
	printf("Inorder\n");
	in(start);
	printf("\n");
	count = 0;
	printf("Postorder\n");




	return 0;
}

void pre(int num){
	if(count==0){
		printf("%d\n", num);
		count++;
	}	
	else printf(" %d\n", num);
	if (tree[num].l != NO) pre(tree[num].l);
	if (tree[num].r != NO) pre(tree[num].r);

}

void in(int num){

	if (tree[num].l != NO) pre(tree[num].l);
	if(count==0){
		printf("%d\n", num);
		count++;
	}	
	else printf(" %d\n", num);
	if (tree[num].r != NO) pre(tree[num].r);


}

void pos(int num){

	if (tree[num].l != NO) pre(tree[num].l);
	if (tree[num].r != NO) pre(tree[num].r);
		if(count==0){
		printf("%d\n", num);
		count++;
	}	
	else printf(" %d\n", num);


}