#include <stdio.h>
struct tree{
	long long l;
	long long r;
	long long f;
}arr[11000];
void Preorder(long long a){
	if(arr[a].l==-1&&arr[a].r==-1){
//		printf("a=%lld  zuo=%lld you=%lld\n",a,arr[a].l ,arr[a].r );
		printf(" %d",a);
		return;
	}else{
//	printf("a=%lld  zuo=%lld you=%lld\n",a,arr[a].l ,arr[a].r );
	printf(" %d",a);
	if(arr[a].l!=-1)Preorder(arr[a].l);
	if(arr[a].r!=-1)Preorder(arr[a].r );	
	}
	
}
void Inorder(long long a){
if(arr[a].l==-1&&arr[a].r==-1){
//		printf("a=%lld  zuo=%lld you=%lld\n",a,arr[a].l ,arr[a].r );
		printf(" %d",a);
		return;
	}else{
	if(arr[a].l!=-1)Inorder(arr[a].l);
    printf(" %d",a);
//	printf("a=%lld  zuo=%lld you=%lld\n",a,arr[a].l ,arr[a].r );
	if(arr[a].r!=-1)Inorder(arr[a].r );	
	}
}

void IPostorder(long long a){
if(arr[a].l==-1&&arr[a].r==-1){
//		printf("a=%lld  zuo=%lld you=%lld\n",a,arr[a].l ,arr[a].r );
		printf(" %d",a);
		return;
	}else{
	if(arr[a].l!=-1)IPostorder(arr[a].l);
	if(arr[a].r!=-1)IPostorder(arr[a].r );
//	printf("a=%lld  zuo=%lld you=%lld\n",a,arr[a].l ,arr[a].r );
	printf(" %d",a);
	}
}
long long found(long long a){
	while(arr[a].f!=-1){
		a=arr[a].f;
	}
	return a;
}
int main() {
    int n;
    while(scanf("%d",&n)!=EOF){
    	for(int i=0;i<10000;i++){
    		arr[i].f =-1;
    		arr[i].r=-1;
    		arr[i].l =-1;
		}
    	long long fa,lc,rc;
    	while(n--){
    		scanf("%lld %lld %lld",&fa,&lc,&rc);
			arr[fa].l=lc;
			arr[fa].r =rc;
			if(lc!=-1)arr[lc].f=fa;
			if(rc!=-1)arr[rc].f=fa; 
		}
	long long father=found(fa);
//	printf("father=%lld",father);
	printf("Preorder\n");
	Preorder(father);
	printf("\nInorder\n");
	Inorder(father);
	printf("\nIPostorder\n");
	IPostorder(father);
	printf("\n");
	}
	return 0;
}

