// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include<unordered_map>
#include <stack>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template<typename T>
inline bool chmin(T &a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template<typename T>
void vdeb(std::vector<T> &da) {
	for (int i = 0;i < da.size();i++) {
		if (i == da.size() - 1) std::cout << da[i];
		else std::cout << da[i] << ' ';
	}
	std::cout << std::endl;
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
	for (int i = 0;i < da.size();i++) vdeb(da[i]);
	std::cout << std::endl;
}

using namespace std;

struct Node{
	int id, parents, slibing, degree, depth, height, left, right;
	Node(){
		id = -1;
		parents = -1;
		slibing = -1;
		degree = -1;
		depth = 0;
		height = 0;
	}
};

struct Tree{
	int size;
	Node *root;
	vector<Node> da;
	Tree() {}
	Tree(int _size) : size(_size){
		da = vector<Node>(size);
		root = nullptr;
		rip(i,size,0) da[i].id = i;
	}
	void construct_parents(){
		rip(i,size,0){
			da[da[i].left].parents = i;
			da[da[i].right].parents = i;
		}
	}
	void construct_sibling(){
		rip(i,size,0) if(da[i].parents == -1) continue; else da[i].slibing = da[da[i].parents].left + da[da[i].parents].right - i;
	}
	void construct_degree(){
		rip(i,size,0) da[i].degree = min(da[i].left,0) + min(da[i].right,0) + 2;
	}
	Node *find_root(){
		rip(i,size,0) if(da[i].parents == -1) return &(*this).da[i];
	}
	void output(){
		rip(i,size,0){
			string state;
			if(da[i].parents == -1) state = "root";
			else if(da[i].degree == 0) state = "leaf";
			else state = "internal node";
			printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s\n",
			i, da[i].parents, da[i].slibing, da[i].degree, da[i].depth, da[i].height, state.c_str());
		}
	}
	void DFS(){
		if(!bool(root)) root = find_root();
		dfs(*root);
	}
	void preOrder(vector<int> &me){
		if(!bool(root)) root = find_root();
		preorder(me, *root);
	}
	void inOrder(vector<int> &me){
		if(!bool(root)) root = find_root();
		inorder(me, *root);
	}
	void postOrder(vector<int> &me){
		if(!bool(root)) root = find_root();
		postorder(me, *root);
	}

	private : void dfs(Node &now){
		if(now.left >= 0){
			Node &next = da[now.left];
			next.depth = now.depth + 1;
			dfs(next);
			chmax(now.height, next.height + 1);
		}
		if(now.right >= 0){
			Node &next = da[now.right];
			next.depth = now.depth + 1;
			dfs(next);
			chmax(now.height, next.height + 1);
		}
	}
	void preorder(vector<int> &me, Node &now){
		me.push_back(now.id);
		if(now.left >= 0){
			preorder(me, da[now.left]);
		}
		if(now.right >= 0){
			preorder(me, da[now.right]);
		}
	}
	void inorder(vector<int> &me, Node &now){
		if(now.left >= 0){
			inorder(me, da[now.left]);
		}
		me.push_back(now.id);
		if(now.right >= 0){
			inorder(me, da[now.right]);
		}
	}
	void postorder(vector<int> &me, Node &now){
		if(now.left >= 0){
			postorder(me, da[now.left]);
		}
		if(now.right >= 0){
			postorder(me, da[now.right]);
		}
		me.push_back(now.id);
	}

};

void vput(vector<int> &da){
	rip(i, da.size(), 0) printf(" %d", da[i]);
	printf("\n");
}

int main(){
	int n; cin >> n;
	Tree tr(n);
	rip(i,n,0){
		int id, left, right; cin >> id >> left >> right;
		tr.da[id].left = left;
		tr.da[id].right = right;
	}
	tr.construct_parents();
	tr.construct_sibling();
	tr.construct_degree();
	tr.DFS();
	vector<int> pre(0), ino(0), post(0);
	tr.preOrder(pre);
	tr.inOrder(ino);
	tr.postOrder(post);
	printf("Preorder\n");vput(pre);
	printf("Inorder\n");vput(ino);
	printf("Postorder\n");vput(post);
	return 0;
}


Measured memory_bytes: 3292