#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };


struct MyStruct
{
	int parent = -1;
	int right = -1;
	int left = -1;
	int depth = 0;
	int height = 0;
	int sibling = -1;
	int degree = 0;
	int me = 0;
};

int n, maxRight = 0;
vector<MyStruct>list(100);

int func(int index, int cnt) {

	list[index].depth = cnt;
	if (list[index].left != -1) { func(list[index].left, cnt + 1); }
	if (list[index].right != -1) { func(list[index].right, cnt + 1); }

	return 0;
}

int funcRight(int index) {

	if (list[index].right != -1) {
		funcRight(list[index].right);
	}
	else {
		maxRight = index;
	}

	return 0;
}

int cnt = 0;

int pre(int index) {

	cout << list[index].me;
	cnt++;
	//if (list[index].me != maxRight) {
	if (cnt < n ) {
		cout << " ";
	}
	else {
		cout << endl;
	}

	if (list[index].left != -1) {
		pre(list[index].left);
	}

	if (list[index].right != -1) {
		pre(list[index].right);
	}

	return 0;
}

int ino(int index) {


	if (list[index].left != -1) {
		ino(list[index].left);
	}

	//if (list[index].left == -1) {
		cout << index;
		cnt++;
		//if (index != maxRight) {
		if (cnt < n ) {
			cout << " ";
		}
		else {
			cout << endl;
		}
	//}

	if (list[index].right != -1) {
		ino(list[index].right);
	}

	return 0;
}

int pos(int index) {

	if (list[index].left != -1) {
		pos(list[index].left);
	}

	if (list[index].right != -1) {
		pos(list[index].right);
	}

	cout << index;
	cnt++;
	//if ( list[index].parent != -1) {
	if (cnt < n ) {
		cout << " ";
	}
	else {
		cout << endl;
	}


	return 0;
}


int main() {
	int i, j;



	cin >> n;


	for (i = 0; i < n; i++) {
		int num1, num2, num3;
		cin >> num1 >> num2 >> num3;

		list[num1].left = num2;
		list[num1].right = num3;

		if (num2 != -1) {
			list[num2].parent = num1;
			list[num2].sibling = num3;
		}

		if (num3 != -1) {
			list[num3].parent = num1;
			list[num3].sibling = num2;
		}

		list[num1].me = num1;

	}


	for (i = 0; i < n; i++) {
		if (list[i].right == -1 && list[i].left == -1) {
			list[i].height = 0;
		}
	}

	for (i = 0; i < n; i++) {
		if (list[i].left == -1 && list[i].right == -1) {
			int num = list[i].parent;
			int cnt = 0;

			do {
				if (num == -1) break;
				cnt++;
				list[num].height = max(cnt, list[num].height);
				num = list[num].parent;
				//              if (num == -1) break;
			} while (num != -1);

		}
	}

	int parent;

	for (i = 0; i < n; i++) {
		if (list[i].parent == -1) {
			parent = i;
			break;
		}
	}

	//func(parent, 0);
	funcRight(parent);
	cout << "Preorder" << endl;
	cout << " ";
	pre(parent);

	cnt = 0;
	cout << "Inorder" << endl;
	cout << " ";
	ino(parent);

	cnt = 0;
	cout << "Postorder" << endl;
	cout << " ";
	pos(parent);




	//for (i = 0; i < n; i++) {
	//	if (list[i].left != -1 && list[i].right != -1) {
	//		list[i].degree = 2;
	//	}
	//	else if (list[i].left != -1 || list[i].right != -1) {
	//		list[i].degree = 1;
	//	}
	//}

	//for (i = 0; i < n; i++) {
	//	cout << "node " << i << ": parent = " << list[i].parent << ", sibling = " << list[i].sibling << ", degree = " << list[i].degree << ", depth = " << list[i].depth << ", height = " << list[i].height << ", ";

	//	if (list[i].parent == -1) {
	//		cout << "root" << endl;
	//	}
	//	else if (list[i].left != -1 || list[i].right != -1) {
	//		cout << "internal node" << endl;
	//	}
	//	else if (list[i].left == -1 || list[i].right == -1) {
	//		cout << "leaf" << endl;
	//	}
	//}






	getchar();
	getchar();
	return 0;
}


Measured memory_bytes: 3116