#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#define ll long long
#define vll vector<ll>
#define vst vector<string>
#define vvll(a,h,w) vector<vll> a(h,vll(w))
#define dou(s) atof(s.c_str())
#define lon(s) atoll(s.c_str())
#define str(n) to_string(n)
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(ll i=b;i>=a;i--)
#define ALL(a) a.begin(),a.end()
#define rALL(a) a.rbegin(),a.rend()
#define fion(n) fixed<<setprecision(n)
#define endl "\n"
#define OR ||
#define AND &&
#define NOT !
#define line(s) getline(cin,s)
#define mav(a) (*max_element(ALL(a)))
#define miv(a) (*min_element(ALL(a)))
#define prque priority_queue
#define MOD 1000000007ll
using namespace std;
void solve();
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
}

//ペア配列の整理
struct pea { ll n, m; };
void msort(vector<pea> &a, ll k = 634) {
	struct hikakukansu {
		static bool unstable(const pea &x, const pea &y) { return x.m < y.m; }
		static bool stable(const pea &x, const pea &y) { return (x.m == y.m ? x.n < y.n : x.m < y.m); }
	};
	if (k == 634)sort(ALL(a), hikakukansu::unstable);
	else sort(ALL(a), hikakukansu::stable);
}

//nCk(mod p)
ll fac[510000], finv[510000], inv[510000];
void cmodf(ll p = MOD) {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	rep(i, 2, 510000) {
		fac[i] = fac[i - 1] * i%p;
		inv[i] = p - inv[p%i] * (p / i) % p;
		finv[i] = finv[i - 1] * inv[i] % p;
	}
}
ll cmod(ll n, ll k, ll p = MOD) {
	return fac[n] * (finv[k] * finv[n - k] % p) % p;
}

//keyの小さい方から探していった時に初めてvalueがjoken以上になる時のkey（keyが増えたらvalueも増えるか同じになるとき）
ll value(ll key) {
	/*変更*/
	return 0;
}
ll mini(ll lkey, ll rkey/*ここも調べる*/, ll joken) {
	ll mkey;
	while (lkey != rkey) {
		mkey = (lkey + rkey) / 2;
		if (value(mkey) >= joken)rkey = mkey;
		else lkey = mkey + 1;
	}
	return rkey;
}

//最大公約数
ll gcd(vector<ll> a) {
	rep(i, 1, a.size()) {
		ll k = a[i - 1] % a[i];
		while (k != 0) {
			a[i - 1] = a[i];
			a[i] = k;
			k = a[i - 1] % a[i];
		}
	}
	return a.back();
}

//最小公倍数
ll lcm(vector<ll> a) {
	ll n;
	rep(i, 1, a.size()) {
		n = a[i - 1] * a[i];
		ll k = a[i - 1] % a[i];
		while (k != 0) {
			a[i - 1] = a[i];
			a[i] = k;
			k = a[i - 1] % a[i];
		}
		n /= a[i];
		a[i] = n;
	}
	return n;
}

//Find_after_Sort or Find_String
ll fist(const vector<ll> &a, ll n) {
	if (a.back() < n)return -1;
	ll k = lower_bound(ALL(a), n) - a.begin();
	if (a[k] == n)return k;
	return -1;
}
ll fist(string s, char c) { return (int)s.find(c); }
ll fist(string s, string t) { return (int)s.find(t); }

//変数定義
vll cl, cr;

//再帰関数
void rec1(ll i) {
	if (i != -1) {
		cout << " " << i;
		rec1(cl[i]);
		rec1(cr[i]);
	}
}
void rec2(ll i) {
	if (i != -1) {
		rec2(cl[i]);
		cout << " " << i;
		rec2(cr[i]);
	}
}
void rec3(ll i) {
	if (i != -1) {
		rec3(cl[i]);
		rec3(cr[i]);
		cout << " " << i;
	}
}
//アルゴリズム
void solve() {
	ll n; cin >> n;
	vll p(n, -1);
	rep(i, 0, n) { cl.push_back(0); cr.push_back(0); }
	rep(i, 0, n) {
		ll id, l, r;
		cin >> id >> l >> r;
		if (l != -1)p[l] = id;
		if (r != -1)p[r] = id;
		cl[id] = l;
		cr[id] = r;
	}

	ll r;
	rep(i, 0, n)if (p[i] == -1) { r = i; break; }

	cout << "Preorder" << endl;
	rec1(r);
	cout << endl;

	cout << "Inorder" << endl;
	rec2(r);
	cout << endl;

	cout << "Postorder" << endl;
	rec3(r);
	cout << endl;
}


Measured memory_bytes: 3188