////////////////////////////////////////
//ALDS1_7_B:   Binary Trees
//
//??????????????????????????¨
////////////////////////////////////////

#include <iostream>
#include <algorithm> // next_permutation
#include <iomanip>
#include <cmath>
#include <vector>
#include <sstream>
#include <string>
#include <cstdio>
#include <stack>
#include <queue>
#include <list>
#include <numeric> //accumulate
//#include <unordered_map> //???????????\??¢??°
#include <fstream> //ifstream, ofstream

//#define NDEBUG //NDEBUG???#include <cassert>???????????????????????????????????´???assert?????????????????????????????????NDEBUG?????????????????????????????????????????????
#include <cassert> //assert


using namespace std;

//???????????°??????TEST????????????????????¬???????????????????????????????????¢????????????
#define TEST //*******************************************************************************************************************************************
//?????????????????¨??§?????\????????????????????????????????°?????????????¨???????????????????dout???????????????????????§???????????¬??????????????????????????????????????????
//??????????????????????????????????????????????????????????§?CPU???????£??????????????????§???TLE?????????????????????????????????????????§????????¨???                           ????????????????????????cerr????????£????????????????????????????????????
#ifdef TEST
#define dout cout
#else
stringstream dummy; //???????????°??????dout?????????????????????????????????
#define dout dummy.str(""); dummy.clear(stringstream::goodbit); dummy //dummy?????????????????????????????????????????¨?????¢?????¢???????????????
//???????????¨??????????????????goodbit?????????????????????????????¨???????????´????????????????????????????????¨?????°?????????????????§???????????????????????????????????? http://d.hatena.ne.jp/linden/20060427/p1
#endif

//?¨??????????????????????????????????????????????????????´??????OUTPUT2TEXTFILE????????????????????¬???????????????????????????????????¢????????????
//#define OUTPUT2TEXTFILE //*******************************************************************************************************************************************
#ifdef OUTPUT2TEXTFILE
#define dout outputfile //??¨????????????TLE????????§?????????dout?????¨??¨??????????????¢????????????????????????????????????????????§????¨????????????´??????????????£??????????????????????¨?????????????????????????????????????????????§?????????????????????
//TEST??????????????????????????¨???outputfile??????????????????????????????
#define OUTPUTFILENAME "output.txt"
ofstream outputfile(OUTPUTFILENAME);
#define OutputFilePath "/Users/Nag/Documents/Prgm/Test/DerivedData/Test/Build/Products/Debug/output.txt"
#endif

#define disp(A) dout << #A << " = " << (A) << endl
#define disP(A) dout << setw(3) << (A) << " " // << setw(3) ??????????????\????????????
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)

#define dispAll(A,n) dout << #A << " = "; rep(j, 0, (n)) {disP(A[j]);} dout << endl

typedef pair<int,int> pii;
typedef vector<int> vi;
typedef unsigned long long ll;

const int INF = 1e9-1;

class Node;

vector<Node> node;


class Node {
public:
    Node() {
        parent = -1;
        left = -1;
        right = -1;
    }
    
    int parent;
    int left;
    int right;
    
    
    int depth() {
        int p = this->parent;
        int d = 0;
        
        while( p != -1 ) {
            d++;
            p = node[p].parent;
        }
        
        return d;
    }
    
    static int height(int id) {
        if(id == -1) return -1;
        
        return max( height(node[id].left), height(node[id].right)) + 1;
    }
    
    static void printNodePreorder(int id) {
        if(id==-1) return;
        
        cout << " " << id;
        printNodePreorder(node[id].left);
        printNodePreorder(node[id].right);
    }
    
    static void printNodeInorder(int id) {
        if(id==-1) return;
        
        printNodeInorder(node[id].left);
        cout << " " << id;
        printNodeInorder(node[id].right);
    }
    
    static void printNodePostorder(int id) {
        if(id==-1) return;
        
        printNodePostorder(node[id].left);
        printNodePostorder(node[id].right);
        cout << " " << id;
    }
    
    
};



int main(){
    int N; cin >> N;
    rep(i,0,N) node.push_back(*new Node());
    
    //read input data
    int p, c1, c2;
    rep(i,0,N) {
        //        dout<<"------";
        //        disp(i);
        cin >> p >> c1 >> c2;
        
        node[p].left = c1;
        node[p].right = c2;
        
        if(c1!=-1) node[c1].parent = p;
        if(c2!=-1) node[c2].parent = p;
        
        
        
    }
    
    
//    //test display
//    rep(i,0,N) {
//        disP(i);
//        disP(node[i].left); disP(node[i].right); disP(node[i].parent);
//        dout << endl;
//    }
    
    
//    //output
//    rep(i,0,N) {
//        cout << "node " << i << ": parent = " << node[i].parent
//        << ", sibling = " << (node[i].parent==-1 ? -1 : (node[node[i].parent].left==i ? node[node[i].parent].right : node[node[i].parent].left) )
//        << ", degree = " << (node[i].left==-1 ? (node[i].right==-1 ? 0 : 1) : (node[i].right==-1 ? 1 : 2))
//        << ", depth = " << node[i].depth()
//        << ", height = " << Node::height(i) << ", "
//        << (node[i].parent==-1 ? "root" : (node[i].left==-1 && node[i].right==-1 ? "leaf" : "internal node") ) << endl;
//    }
    
    
    //find root
    int root_i = -1;
    rep(i,0,N) {
        if(node[i].parent==-1) {
            root_i = i;
            break;
        }
    }
    assert(root_i!=-1);
    
    //print tree
    cout << "Preorder\n";
    Node::printNodePreorder(root_i);
    cout << endl;
    
    cout << "Inorder\n";
    Node::printNodeInorder(root_i);
    cout << endl;
    
    cout << "Postorder\n";
    Node::printNodePostorder(root_i);
    cout << endl;
    
    
#ifdef OUTPUT2TEXTFILE
    outputfile.close();
    cout << "\"" << OutputFilePath << "\"" << endl;
#endif
    
    return 0;
}

Measured memory_bytes: 3100