#include <stdio.h>          // printf(), scanf()
#define MAX_N 25

typedef struct node_tbl
{
	int parent;
	int left;
	int right;
} node;

const int nil = -1;
node t[MAX_N];

void
preparse(int u) /* ??????????????? */
{
	if (u == nil)
		return;

	printf(" %d", u);
	preparse(t[u].left);
	preparse(t[u].right);
}

void
inparse(int u) /* ??????????????? */
{
	if (u == nil)
		return;

	inparse(t[u].left);
	printf(" %d", u);
	inparse(t[u].right);
}

void
postparse(int u) /* ??????????????? */
{
	if (u == nil)
		return;

	postparse(t[u].left);
	postparse(t[u].right);
	printf(" %d", u);
}

int
main(int argc, char** argv)
{
	int n;
	int root;
	int v;
	int l, r;
	int i;

	scanf("%d", &n);
	for (i = 0; i < n; ++i)
		t[i].parent = nil;

	for (i = 0; i < n; ++i)
	{
		scanf("%d %d %d", &v, &l, &r);
		t[v].left = l;
		t[v].right = r;
		if (l != nil)
			t[l].parent = v;

		if (r != nil)
			t[r].parent = v;
	}

	for (i = 0; i < n; ++i)
	{
		if (t[i].parent == nil)
		{
			root = i;
			break;
		}
	}

	printf("Preorder\n");
	preparse(root);
	printf("\n");

	printf("Inorder\n");
	inparse(root);
	printf("\n");

	printf("Postorder\n");
	postparse(root);
	printf("\n");

	return 0;
}