#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl
#define printD(a) cout << setprecision(15) << (a) << endl;
using namespace std;
int max_int = 2147483647;
int prime = 998244353;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<auto>& a,int n);
double PI = 3.14159265358979;
int n;



struct Node{
    int parent=-1;
    int left=-1,right=-1;
};

class BinaryTree{
    vector<Node> tree;
    vector<int> tree_depth;
    public:
    BinaryTree(int n){
        this->tree.resize(n);
        this->tree_depth.resize(n,-1);
    }
    BinaryTree(){
        this->tree.resize(10e6);
        this->tree_depth.resize(10e6,-1);
    }

    void make_leaf(int parent,int child){
        if(tree[parent].left == -1){tree[parent].left = child;}
        else if(tree[parent].right != -1){printf("Error. Node has more than three child.\n");return;}
        else{tree[parent].right = child;}
        tree[child].parent = parent;
    }
    void make_leaf(int parent,int left,int right){
        tree[parent].left = left;
        tree[parent].right = right;
        tree[left].parent = parent;
        tree[right].parent = parent;
    }

    int depth(int n){
        if(tree_depth[n] != -1) return tree_depth[n];
        int tmp = n;
        //根を探索
        while(tree[tmp].parent != -1){
            tmp = tree[tmp].parent;
        }
        tree_depth[tmp] = 0;
        queue<int> q;
        if(tree[tmp].left != -1) q.push(tree[tmp].left);
        if(tree[tmp].right != -1) q.push(tree[tmp].right);
        while(!q.empty()){
            tmp = q.front();
            q.pop();
            tree_depth[tmp] = tree_depth[tree[tmp].parent]+1;
            if(tree[tmp].left != -1) q.push(tree[tmp].left);
            if(tree[tmp].right != -1) q.push(tree[tmp].right);
        }
        return tree_depth[n];
    }
    int height(int n){
        int h = 0;
        queue<P> q;
        if(tree[n].left != -1) q.push(P(tree[n].left,1));
        if(tree[n].right != -1) q.push(P(tree[n].right,1));
        while(!q.empty()){
            P p = q.front();q.pop();
            h = max(h,p.second);
            if(tree[p.first].left != -1) q.push(P(tree[p.first].left,p.second+1));
            if(tree[p.first].right != -1) q.push(P(tree[p.first].right,p.second+1));
        }
        return h;
    }
    void Deb(){
        Debug(tree_depth);
    }
    void dfs_i(int n){
        if(n == -1) return;
        dfs_i(tree[n].left);
        cout << " " << n;
        dfs_i(tree[n].right);
    }
    void dfs_p(int n){
        if(n == -1) return;
        dfs_p(tree[n].left);
        dfs_p(tree[n].right);
        cout << " " << n;
    }
    void print_AOJ(){
        int n;
        REP(i,tree.size()){
            if(tree[i].parent == -1){
                n=i;
                break;
            }
        }
        print("Preorder");
        cout << " " << n;
        stack<int> s;
        s.push(tree[n].right);
        s.push(tree[n].left);
        while(!s.empty()){
            int t = s.top();s.pop();
            if(t==-1) continue;
            cout << " " << t;
            s.push(tree[t].right);
            s.push(tree[t].left);
        }
        print("");
        print("Inorder");
        dfs_i(n);
        print("");
        print("Postorder");
        dfs_p(n);
        print("");
    }

};



void print_AOJ(auto a){
    REP(i,a.size()){
        if(i){
            cout << " ";
        }
        cout << a[i];
    }
    cout << "\n";
}


signed main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    cin >> n;
    BinaryTree t(n);
    REP(i,n){
        int p,l,r;
        cin >> p >> l >> r;
        t.make_leaf(p,l,r);
    }
    t.print_AOJ();

    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}

//key以上の初めてのitr
int nibul(auto a,auto b){return lower_bound(All(a),b) - a.begin();}
//key以下の最後のitr
int nibuu(auto a,auto b){return upper_bound(All(a),b) - a.begin()-1;}

void input(vector<auto>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}



Measured memory_bytes: 3236