#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <algorithm>
#include <array>

using namespace std;

class Tree;

class Node {
public:
	enum KindOfNode {
		ROOT, LEAF, INTERNAL
	};
	enum NEIGHBOUR {
		PARENT = 0, LEFT = 1, RIGHT = 2, ME = 3
	};
	Node(Tree* tree);
	int& parent() { return nearNodes.at(NEIGHBOUR::PARENT); }
	int& left() { return nearNodes.at(NEIGHBOUR::LEFT); }
	int& right() { return nearNodes.at(NEIGHBOUR::RIGHT); }
	int parent()const { return nearNodes.at(NEIGHBOUR::PARENT); }
	int left() const { return nearNodes.at(NEIGHBOUR::LEFT); }
	int right() const { return nearNodes.at(NEIGHBOUR::RIGHT); }
	int me()const;
	int getNeighbour(const NEIGHBOUR& n)const {
		if (n == NEIGHBOUR::ME) return me();
		return nearNodes.at(n);
	}
	string getKind() const;
	int getSibling()const;
	int getDeg()const;

	Tree* tree;
	array<int, 3> nearNodes;//parent, left, right;
	int depth;//cache
	int height;//cache
	string kind;
};



class Tree {
public:
	vector<Node> nodes;
	template<typename T>
	void init(T& cin) {
		int n;
		cin >> n;
		nodes.resize(n, Node(this));
		for (int i = 0; i != n; ++i) {
			int id; cin >> id;
			Node& node = nodes.at(id);
			cin >> node.left();
			cin >> node.right();
			if (node.left() != -1) {
				nodes.at(node.left()).parent() = id;
			}
			if (node.right() != -1) {
				nodes.at(node.right()).parent() = id;
			}
		}

		rootNodeID = distance(nodes.begin(), find_if(nodes.begin(), nodes.end(), [](const Node& node) {return node.parent() == -1; }));

		//深さ
		{
			function<void(int, int)> setDepth = [&](const int nodeID, const int d) {
				Node& targetNode = nodes.at(nodeID);
				targetNode.depth = d;
				if (targetNode.left() != -1) setDepth(targetNode.left(), d + 1);
				if (targetNode.right() != -1) setDepth(targetNode.right(), d + 1);
			};
			setDepth(rootNodeID, 0);
		}

		//高さ
		{
			function<int(int)> setHeight = [&](const int nodeID) {
				if (nodeID == -1)return -1;
				Node& targetNode = nodes.at(nodeID);
				const int heightL = setHeight(targetNode.left());
				const int heightR = setHeight(targetNode.right());
				return targetNode.height = max(heightL, heightR) + 1;
			};
			setHeight(rootNodeID);
		}

	}

	int rootNodeID;

	void printNodesInfo()const;

	void printVisitNodeIDInSpecifiedOrder(const initializer_list<Node::NEIGHBOUR>& visitOrder ) {
		function<void(int)> visitImpl = [&](int nodeID) {
			const Node& node = nodes.at(nodeID);
			const int me = node.me();
			for (const auto& n : visitOrder) {
				const int visitNodeID = node.getNeighbour(n);
				if (visitNodeID == me) cout << " " << me;
				else if (visitNodeID != -1) visitImpl(visitNodeID);
			}
		};
		visitImpl(rootNodeID);
	}
};

Node::Node(Tree* treePtr) : tree(treePtr), nearNodes({ -1, -1, -1 }){}

int Node::me()const { return distance(&tree->nodes.front(), const_cast<Node*>(this)); }

string Node::getKind() const {
	if (parent() == -1)return "root";
	if (left() != -1 || right() != -1)return "internal node";
	return "leaf";
}
int Node::getSibling()const {
	if (parent() == -1)return -1;
	const Node& parentNode = tree->nodes.at(parent());
	const int id = distance(&tree->nodes.front(), const_cast<Node*>(this));
	return parentNode.right() == id ? parentNode.left() : parentNode.right();
}
int Node::getDeg()const {
	int deg = 0;
	if (left() != -1)++deg;
	if (right() != -1)++deg;
	return deg;
}

void Tree::printNodesInfo()const {
	const size_t n = nodes.size();
	for (size_t i = 0; i != nodes.size(); ++i) {
		const Node& node = nodes.at(i);//getSibling
		cout << "node " << i
			<< ": parent = " << node.parent()
			<< ", sibling = " << node.getSibling()
			<< ", degree = " << node.getDeg()
			<< ", depth = " << node.depth 
			<< ", height = " << node.height
			<< ", " << node.getKind()
			<< endl;
	}
}

int main()
{
	Tree tree;
	tree.init(cin);
	//tree.printNodesInfo();
	cout << "Preorder" << endl;
	using NN = Node::NEIGHBOUR;
	tree.printVisitNodeIDInSpecifiedOrder({ NN::ME, NN::LEFT ,NN::RIGHT });
	cout<<endl;
	cout << "Inorder" << endl;
	tree.printVisitNodeIDInSpecifiedOrder({ NN::LEFT, NN::ME ,NN::RIGHT });
	cout<<endl;
	cout << "Postorder" << endl;
	tree.printVisitNodeIDInSpecifiedOrder({ NN::LEFT, NN::RIGHT ,NN::ME });
	cout<<endl;


	return 0;
}


Measured memory_bytes: 3156