#include <stdio.h>
#define MAX 100000000
#define noParent -1

struct Node{
	int id, l, r;
};

struct Node box[MAX];

void preParse(int u){
	if ( u == noParent ) return;
	printf(" %d", u);
	preParse(box[u].l);
	preParse(box[u].r);
}

void inParse(int u){
	if ( u == noParent ) return;
	inParse(box[u].l);
	printf(" %d", u);
	inParse(box[u].r);
}

void postParse(int u){
	if ( u == noParent ) return;
	postParse(box[u].l);
	postParse(box[u].r);
	printf(" %d", u);
}

int main () {
	int i,n,id,left,right,root;
	
	scanf("%d",&n);
	for(i=0;i<n;i++) {
		box[i].id = noParent;
	}
	
	for(i=0;i<n;i++) {
		scanf("%d %d %d",&id,&left,&right);
		box[id].l = left;
		box[id].r = right;
		if ( left != noParent ) box[left].id = id;
		if ( right != noParent ) box[right].id = id;
	}
	
	for ( i = 0; i < n; i++ ) {
		if ( box[i].id == noParent ) root = i;
	}
	
	for (i = 0;i < n; i++)  if ( box[id].id == noParent ) root = i;
	printf("Preorder\n");
	preParse(root);
	printf("\n");
	printf("Inorder\n");
	inParse(root);
	printf("\n");
	printf("Postorder\n");
	postParse(root);
	printf("\n");

	return 0;
}











