#include<iostream>
#include<memory>
#include<vector>

/*
struct binary_tree {
	int id;
	std::unique_ptr<binary_tree> left, right;
	binary_tree(int id_) :id{ id_ }, left{}, right{}{}

	auto find(int id_)-> binary_tree* {
	//	std::cout <<"find now... "<< id_ << "\n";
		/*if (id_ == -1)
			return nullptr;

		if (id_ == this->id)
			return this;
		else {
			auto*lp = left?left->find(id_):nullptr;
			return lp != nullptr? lp
				:	right?right->find(id_):nullptr;
		}
		return nullptr;
	}

	auto find(int id_)const ->const binary_tree* {
		return const_cast<const binary_tree*>(
			const_cast<binary_tree*>(this)->find(id)
			);
	}

};



auto make(int id_,int left_ = -1, int right_ = -1)
	->std::unique_ptr< binary_tree > {
	auto ptr = std::make_unique<binary_tree>(id_);
	if (left_ != -1)
		ptr->left = make(left_) ;

	if (right_ != -1)
		ptr->right = make(right_);

	return ptr;
}

namespace {
	auto print_id(binary_tree*bt) {
		if (bt->id != -1)
			std::cout << " " << bt->id;
	}
	template<class F>
	auto go_left(binary_tree*bt, F f) {
		if ( bt->left )
			f(bt->left.get());
	}

	template<class F>
	auto go_right(binary_tree*bt, F f) {
		if (bt->right)
			f(bt->right.get());
	}
}



void pre_order(binary_tree*bt, int size, int& count ) {
//	std::cout <<"["<< size << " " << count <<"]" <<"\n";

	if (bt->id != -1) {
		std::cout << " ";
		std::cout << bt->id;
		std::cout << (count == size-1 ? "\n" : "");
		++count;
	}

	if (bt->left) {
		//std::cout << " ";
		pre_order(bt->left.get(),size,count);
	}

	if (bt->right) {
		//std::cout << " ";
		pre_order(bt->right.get(),size, count);
	}

}

void in_order(binary_tree*bt) {
//	std::cout << "\n["<<bt->id << "]\n";

	go_left(bt, in_order);

	print_id(bt);

	go_right(bt, in_order);

}

void post_order(binary_tree*bt) {
	go_left(bt, post_order);
	go_right(bt, post_order);
	print_id(bt);
}
*/

/*
int deprecated() {
	int n;
	std::cin >> n;

	int id, l, r;
	std::cin >> id >> l >> r;
	auto root = make(id, l, r);
	

	for (int i{ 1 }; i < n; ++i) {
		std::cin >> id >> l >> r;
		auto* p = root->find(id);
		p->left = make(l);
		p->right = make(r);
	}


	int c{};//dirty counter;
	std::cout << "Preorder\n";
	pre_order(root.get(),n,c);


	std::cout << "Inorder\n";
	in_order(root.get() );
	std::cout << "\n";


	std::cout << "Postorder\n";
	post_order(root.get());
	std::cout << "\n";
//	std::cout << "//\n";
	return 0;
}

*/


struct node{
	int id;
	int parent;
	int left, right;
	node(int id_,int parent_ = -1, int l_ = -1, int r_ = -1):
		id{id_}
		, parent{parent_}
		, left{ l_ }
		, right{r_}{}


	node() : id{}, parent{-1}, left{}, right{}{}

	friend
	std::istream& operator>>(std::istream&is, node&n) {
		return is >> n.id >> n.left >> n.right;
	}

	friend
		std::ostream& operator<<(std::ostream&os, const node&n) {
		return os << n.id << n.left << n.right;
	}
};

auto pre_order(const std::vector<node>& v,int index)->void {
	if (index == -1)
		return;

	auto& here = v[index];
	std::cout << " " << v[index].id;
	pre_order(v, here.left);
	pre_order(v, here.right);
}

auto in_order(const std::vector<node>& v, int index)->void {
	if (index == -1)
		return;
	
	auto& here = v[index];
	in_order(v, here.left);
	std::cout << " " << v[index].id;
	in_order(v, here.right);

}

auto post_order(const std::vector<node>& v, int index)->void {

	if (index == -1)
		return;
	auto& here = v[index];
	post_order(v, here.left);
	post_order(v, here.right);
	std::cout << " " << v[index].id;
}

int main(){
	int n;
	std::cin >> n;
	std::vector<node> tree;
	tree.resize(n);

	for (int i{}; i < n; ++i) {
		int id;
		std::cin >> id; //tree[i];

		tree[id].id = id;
		std::cin >> tree[id].left >> tree[id].right;

//		std::cout << tree[id]<<"\n";

		if(tree[id].left != -1)
			tree[tree[id].left].parent = id;

		if (tree[id].right != -1)
			tree[tree[id].right].parent = id;
	}
	
/*	for (auto&e : tree) 
		std::cout << e << " parent = " <<e.parent<< "\n";
	*/

	auto root_i = 0;
	for (int i{}; i < n; ++i) {
		if (tree[i].parent == -1) {
			root_i = i;
			break;
		}
	}
//	std::cout << "ROOT = " << root_i<<"\n";


	std::cout << "Preorder\n";
	pre_order(tree, root_i);
	std::cout << "\n";


	std::cout << "Inorder\n";
	in_order(tree, root_i);
	std::cout << "\n";


	std::cout << "Postorder\n";
	post_order(tree, root_i);
	std::cout << "\n";
}


Measured memory_bytes: 3088