#include <stdio.h>
#include <stdlib.h>

struct node {
	int car;
	int cdr;
	int parent;
	int sibling;
};

void
preorder(struct node *a, int x)
{
	printf(" %d", x);

	if (a[x].car >= 0)
		preorder(a, a[x].car);

	if (a[x].cdr >= 0)
		preorder(a, a[x].cdr);
}

void
inorder(struct node *a, int x)
{
	if (a[x].car >= 0)
		inorder(a, a[x].car);

	printf(" %d", x);

	if (a[x].cdr >= 0)
		inorder(a, a[x].cdr);
}

void
postorder(struct node *a, int x)
{
	if (a[x].car >= 0)
		postorder(a, a[x].car);

	if (a[x].cdr >= 0)
		postorder(a, a[x].cdr);

	printf(" %d", x);
}

int
main(void)
{
	int i, j, n, r;
	struct node *a;

	scanf("%d", &n);

	a = (struct node *)malloc(sizeof(struct node) * n);
	if (a == NULL)
		return 1;

	for (i = 0; i < n; i++) {
		a[i].parent = -1;
		a[i].sibling = -1;
	}

	for (i = 0; i < n; i++) {
		int id, car, cdr;
		scanf("%d%d%d", &id, &car, &cdr);
		a[id].car = car;
		a[id].cdr = cdr;
		car >= 0 && (a[car].parent = id);
		cdr >= 0 && (a[cdr].parent = id);
		if (car >= 0 && cdr >= 0)
			a[cdr].sibling = car, a[car].sibling = cdr;
	}

	for (r = 0; r < n - 1; r++)
		if (a[r].parent == -1)
			break;

	printf("Preorder\n");
	preorder(a, r);
	printf("\n");

	printf("Inorder\n");
	inorder(a, r);
	printf("\n");

	printf("Postorder\n");
	postorder(a, r);
	printf("\n");

	return 0;
}

