#include <iostream>
using namespace std;
#define MAX 10000
#define NIL -1


typedef struct Node
{
	int number;
	int parent;
	int left, right;
	int depth;
	int height; // 自分と自分から一番深い子の距離
};

void setDepth(Node node[], int index, int depth)
{
	if (index == NIL) return;
	node[index].depth = depth;
	setDepth(node, node[index].left, depth + 1);
	setDepth(node, node[index].right, depth + 1);
}

int setHeight(Node node[], int index, int height)
{
	int h1 = 0, h2 = 0;
	if (node[index].left != NIL)
		h1 = setHeight(node, node[index].left, node[node[index].left].height) + 1;
	if (node[index].right != NIL)
		h2 = setHeight(node, node[index].right, node[node[index].right].height) + 1;
	return node[index].height = h1 > h2 ? h1 : h2;
}

int getSibling(Node node[], int index)
{
	if (node[index].parent == NIL) return NIL;
	if (node[node[index].parent].left != index && node[node[index].left].number != NIL)
		return node[node[index].parent].left;
	if (node[node[index].parent].right != index && node[node[index].right].number != NIL)
		return node[node[index].parent].right;
	return NIL;
}

int getDegree(Node node)
{
	int deg = 0;
	if (node.left != NIL) deg++;
	if (node.right != NIL) deg++;
	return deg;
}

void print(Node node[], int n)
{
	for (int i = 0; i < n; i++)
	{
		cout << "node " << node[i].number << ": ";
		cout << "parent = " << node[i].parent << ", ";
		cout << "sibling = " << getSibling(node, i) << ", ";
		cout << "degree = " << getDegree(node[i]) << ", ";
		cout << "depth = " << node[i].depth << ", ";
		cout << "height = " << node[i].height << ", ";
		if (node[i].parent == NIL)
			cout << "root";
		else if (node[i].left == NIL && node[i].right == NIL)
			cout << "leaf";
		else
			cout << "internal node";
		cout << endl;
	}
}

void preOrder(Node node[], int index)
{
	if (index == NIL) return;
	cout << " " << node[index].number;
	preOrder(node, node[index].left);
	preOrder(node, node[index].right);
}

void inOrder(Node node[], int index)
{
	if (index == NIL) return;
	inOrder(node, node[index].left);
	cout << " " << node[index].number;
	inOrder(node, node[index].right);
}
void postOrder(Node node[], int index)
{
	if (index == NIL) return;
	postOrder(node, node[index].left);
	postOrder(node, node[index].right);
	cout << " " << node[index].number;
}

int main()
{
	Node node[MAX];
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		node[i].number = node[i].parent = NIL;
		node[i].left = node[i].right = NIL;
		node[i].depth = node[i].height = 0;
	}
	for (int i = 0; i < n; i++)
	{
		int number;
		cin >> number;
		node[number].number = number;
		cin >> node[number].left >> node[number].right;
		if (node[number].left != NIL) node[node[number].left].parent = node[number].number;
		if (node[number].right != NIL) node[node[number].right].parent = node[number].number;
	}

	int idxRoot;
	for (int i = 0; i < n; i++) if (node[i].parent == NIL) { idxRoot = i; break; }

	setDepth(node, idxRoot, 0);
	setHeight(node, idxRoot, 0);

	cout << "Preorder" << endl;
	preOrder(node, idxRoot);
	cout << endl;
	cout << "Inorder" << endl;
	inOrder(node, idxRoot);
	cout << endl;
	cout << "Postorder" << endl;
	postOrder(node, idxRoot);
	cout << endl;
	//print(node, n);
}


Measured memory_bytes: 3132