#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

// #define DEBUG

struct node
{
    int id = 0;
    int parent = -1;
    node *pp = 0;
    int sibling = -1;
    int left = -1;
    node *lp = 0;
    int right = -1;
    node *rp = 0;
    int degree = 0;
    int depth = -1;
    int height = -1;
    int preorder = -1;
    int inorder = -1;
    int postorder = -1;
    string status = "unknown";
};

void nodeproperty(node &x)
{
    if (x.left != -1)
        x.degree++;
    if (x.right != -1)
        x.degree++;

    if (x.parent == -1)
    {
        x.status = "root";
        if (x.degree == 0)
            x.height = 0;
    }
    else if (x.degree != 0)
        x.status = "internal node";
    else
    {
        x.status = "leaf";
        x.height = 0;
    }
}

void getdepth(node x[], int n)
{
    vector<int> search, new_search;
    int d = 0;
    for (int i = 0; i < n; i++)
    {
        if (x[i].status == "root")
            search.push_back(i);
    }
    while (!search.empty())
    {
        for (auto itr = search.begin(); itr != search.end(); itr++)
        {
            x[*itr].depth = d;
            if (x[*itr].left != -1)
                new_search.push_back(x[*itr].left);
            if (x[*itr].right != -1)
                new_search.push_back(x[*itr].right);
        }

        search.clear();
        search = new_search;
        new_search.clear();
        d++;
    }
}

void getheight(node x[], int n)
{
    vector<int> search, new_search;
    int h = 0;
    for (int i = 0; i < n; i++)
    {
        if (x[i].status == "leaf")
            search.push_back(i);
    }
    while (!search.empty())
    {
        for (auto itr = search.begin(); itr != search.end(); itr++)
        {
            x[*itr].height = h;
            if (x[*itr].parent != -1)
                new_search.push_back(x[*itr].parent);
        }

        search.clear();
        search = new_search;
        new_search.clear();
        h++;
    }
}

void preorder(node *x)
{
    cout << " " << x->id;
    if (x->lp != 0)
        preorder(x->lp);
    if (x->rp != 0)
        preorder(x->rp);
}

void inorder(node *x)
{
    if (x->lp != 0)
        inorder(x->lp);
    cout << " " << x->id;
    if (x->rp != 0)
        inorder(x->rp);
}

void postorder(node *x)
{
    if (x->lp != 0)
        postorder(x->lp);
    if (x->rp != 0)
        postorder(x->rp);
    cout << " " << x->id;
}

void tree_excursion(node *x)
{
    cout << "Preorder" << endl;
    preorder(x);
    cout << endl;
    cout << "Inorder" << endl;
    inorder(x);
    cout << endl;
    cout << "Postorder" << endl;
    postorder(x);
    cout << endl;
}

void printnode(node x)
{
    cout << "node " << x.id << ": parent = " << x.parent;
    cout << ", sibling = " << x.sibling << ", degree = ";
    cout << x.degree << ", depth = " << x.depth << ", height = ";
    cout << x.height << ", " << x.status << endl;
}

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int n, id, left, right, root;
    cin >> n;
    node tree[n];
    for (int i = 0; i < n; i++)
    {
        cin >> id >> left >> right;
        tree[i].id = i;
        tree[id].left = left;
        if (left != -1)
            tree[id].lp = &tree[left];
        tree[id].right = right;
        if (right != -1)
            tree[id].rp = &tree[right];
        tree[left].parent = id;
        tree[left].pp = &tree[id];
        tree[left].sibling = right;
        tree[right].parent = id;
        tree[right].pp = &tree[id];
        tree[right].sibling = left;
    }

    for_each(tree, tree + n, &nodeproperty);
    for (int i = 0; i < n; i++){
        if (tree[i].status == "root")
            root = i;
    }
    tree_excursion(&tree[root]);

    return 0;
}

// getline(cin,s);
// a = strtok(s, ",");  ","で分解
// for (int i = 0; i < n; i++)


Measured memory_bytes: 3220