#include<cstdio>
#include<cstring>
#include<cstdlib>

struct node{
	int data;
	node* lchild;
	node* rchild;
}root[300000];

void preorder(node *root)
{
	if(root == NULL)
		return;
	printf(" %d",root->data);
	preorder(root->lchild);
	preorder(root->rchild);
}

void inorde(node *root)
{
	if(root == NULL)
		return;
	inorde(root->lchild);
	printf(" %d",root->data);
	inorde(root->rchild);
}

void postorder(node *root)
{
	if(root == NULL)
		return;
	postorder(root->lchild);
	postorder(root->rchild);
	printf(" %d",root->data);
}

node* create(node* root1,int n,struct node root[])
{
	if(root1==NULL)
		return NULL;
	for(int i = 0;i < n;i ++)
	{
		if(root1->lchild!=NULL&&root1->lchild->data==root[i].data)
		{
			root1->lchild = &root[i];
			create(&root[i],n,root);
		}
		if(root1->lchild!=NULL&&root1->rchild->data==root[i].data)
		{
			root1->rchild = &root[i];
			create(&root[i],n,root);
		}
	}
}

int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		int a[n];
		int b[n][3];
		int p,q,l;
		memset(a,0,sizeof(a));
		for(int i = 0;i < n;i ++)
		{
			scanf("%d %d %d",&b[i][0],&b[i][1],&b[i][2]);
			root[i].data = b[i][0];
			if(b[i][1]!=-1)
			{
				root[i].lchild = (node*)malloc(sizeof(node));
				root[i].lchild->data = b[i][1];
			}else{
				root[i].lchild = NULL;
			}
			if(b[i][2]!=-1)
			{
				root[i].rchild = (node*)malloc(sizeof(node));
				root[i].rchild->data = b[i][2];
			}else{
				root[i].rchild = NULL;
			}
		}
		for(int i = 0;i < n;i ++)
		{
			for(int j = 0;j < n;j ++)
			{
				if(b[i][0]==b[j][1]||b[i][0]==b[j][2])
				{
					a[i] = 1;
					break;	
				}
			}
		}
		node* root1 = (node*)malloc(sizeof(node));
		/*for(int i = 0;i < n;i ++)
			printf("%d ",a[i]);
		printf("\n");*/
		for(int i = 0;i < n;i ++)
		{
			if(a[i] == 0)
			{
				root1 = &root[i];
				break;
			}
		}
		create(root1,n,root);
		printf("Preorder\n");
		preorder(root1);
		printf("\nInorder\n");
		inorde(root1);
		printf("\nPostorder\n");
		postorder(root1);
		printf("\n");
	}
	return 0;
}
