#define _USE_MATH_DEFINES

#include <array>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <utility>
#include <tuple>
#include <algorithm>
#include <limits>
#include <fstream>
#include <numeric>
#include <stack>
#include <queue>
#include <list>
#include <cstring>
#include <unordered_set>
#include <cmath>
#include <iomanip>

namespace
{
	template<int N>
	std::array<int, N> GetValue(std::istream& stream)
	{
		std::string buf;
		std::getline(stream, buf);

		std::stringstream sstr(buf);
		std::array<int, N> retval;

		for (int i = 0; i < N; ++i)
		{
			std::getline(sstr, buf, ' ');
			retval[i] = std::stoi(buf);
		}

		return retval;
	}

	std::vector<int> GetValue(std::istream& stream, int num, char delim)
	{
		std::string buf;
		std::getline(stream, buf);
		std::stringstream sstr(buf);

		std::vector<int> retval;
		retval.reserve(num);

		std::string input;;
		for (int i = 0; i < num && std::getline(sstr, input, delim); ++i)
		{
			retval.push_back(std::stoi(input));
		}

		return retval;
	}

	int GetValue(std::istream& stream)
	{
		int in;
		stream >> in;

		return in;
	}

	std::vector<std::string> GetValueString(std::istream& stream, int num, char delim)
	{
		std::string buf;
		std::vector<std::string> retval;
		retval.reserve(num);

		std::getline(stream, buf);
		std::stringstream sstr(buf);

		for (int i = 0; i < num && std::getline(sstr, buf, delim); ++i)
		{
			retval.push_back(std::move(buf));
		}

		return retval;
	}

	template<typename Itr>
	void PrintLine(Itr begin, Itr end)
	{
		bool first = true;

		for (int i = 0; begin != end; ++begin, ++i)
		{
			if (!first)
			{
				std::cout << ' ';
			}

			std::cout << (*begin);

			first = false;
		}
		std::cout << std::endl;
	}

	template<typename T>
	void Print(const std::vector<T>& sequence)
	{
		for (const auto& e : sequence)
		{
			std::cout << e << '\n';
		}

		std::cout << std::flush;
	}

	const int kNil = -1;

	struct Node
	{
		int parent;
		int left;
		int right;

		Node()
			: parent(kNil)
			, left(kNil)
			, right(kNil)
		{}
	};

	Node node[25];

	void PreOrder(int num)
	{
		std::cout << ' ' << num;

		if (node[num].left != kNil)
		{
			PreOrder(node[num].left);
		}

		if (node[num].right != kNil)
		{
			PreOrder(node[num].right);
		}
	}

	void InOrder(int num)
	{
		if (node[num].left != kNil)
		{
			InOrder(node[num].left);
		}

		std::cout << ' ' << num;

		if (node[num].right != kNil)
		{
			InOrder(node[num].right);
		}
	}

	void PostOrder(int num)
	{
		if (node[num].left != kNil)
		{
			PostOrder(node[num].left);
		}

		if (node[num].right != kNil)
		{
			PostOrder(node[num].right);
		}

		std::cout << ' ' << num;
	}
}

int main(int argc, char* argv[])
{
	auto file = (argc == 1) ? std::ifstream() : std::ifstream(argv[1]);
	std::istream& stream = (argc == 1) ? std::cin : file;
	if (argc == 1)
	{
		std::cin.tie(0);
		std::ios::sync_with_stdio(false);
	}

	int num = GetValue<1>(stream)[0];

	for (int i = 0; i < num; ++i)
	{
		auto t = GetValue<3>(stream);
		node[t[0]].left = t[1];
		node[t[0]].right = t[2];

		node[t[1]].parent = t[0];
		node[t[2]].parent = t[0];
	}

	int root_num = 0;
	for (int i = 0; i < num; ++i)
	{
		if (node[i].parent == kNil)
		{
			root_num = i;
			break;
		}
	}

	std::cout << "Preorder\n";
	PreOrder(root_num);
	std::cout << '\n';

	std::cout << "Inorder\n";
	InOrder(root_num);
	std::cout << '\n';

	std::cout << "Postorder\n";
	PostOrder(root_num);
	std::cout << '\n';

	std::cout << std::flush;
}



Measured memory_bytes: 3188