#include <stdio.h>

int tree[50];

int search_index(int n)
{
	int i;
	for (i = 0; i < 50; i++) {
		if (n == tree[i]) {
			return i;
		}
	}

	return -1;
}

void preorder_walk(int p) /* root -> left -> right */
{
	if (p >= 50 || tree[p] == -1) {
		return;
	}
	printf(" %d", tree[p]);
	preorder_walk(p*2);
	preorder_walk(p*2 + 1);
}
void inorder_walk(int p) /* left -> root -> right */
{
	if (p >= 50 || tree[p] == -1) {
		return;
	}
	inorder_walk(p*2);
	printf(" %d", tree[p]);
	inorder_walk(p*2 + 1);
}
void postorder_walk(int p) /* left -> right -> root */
{
	if (p >= 50 || tree[p] == -1) {
		return;
	}
	postorder_walk(p*2);
	postorder_walk(p*2 + 1);
	printf(" %d", tree[p]);
}

int main()
{
	int i;
	int n;
	int id, left, right;
	int p;
	for (i = 0; i < 50; i++) {
		tree[i] = -1;
	}

	scanf("%d", &n);

	/* construct tree */
	for (i = 0; i < n; i++) {
		scanf("%d %d %d", &id, &left, &right);
		if (i == 0) {
			tree[1] = id;
			tree[2] = left;
			tree[3] = right;
			continue;
		}
		p = search_index(id);
		tree[p] = id;
		tree[p*2] = left;
		tree[p*2 + 1] = right;
	}

	/* preorder - walk */
	puts("Preorder");
	preorder_walk(1);
	printf("\n");

	/* inorder - walk */
	puts("Inorder");
	inorder_walk(1);
	printf("\n");

	/* postorder - walk */
	puts("Postorder");
	postorder_walk(1);
	printf("\n");
}