#include <iostream>
#include <vector>

using namespace std;

const int NIL = -1;

struct Node {
    int parent;
    int left_child;
    int right_child;
    int depth;
    int height;
};

class BinaryTree {
private:
    vector<Node> nodes;
    int root; // 根のid

    void setNodes(int size)
    {
        for (int i = 0; i < size; i++)
        {
            int id, left, right;
            cin >> id >> left >> right;
            if (left != NIL)
            {
                nodes[id].left_child = left;
                nodes[left].parent = id;
            }
            if (right != NIL)
            {
                nodes[id].right_child = right;
                nodes[right].parent = id;
            }
        }
    }

    void set_depth(int index, int depth)
    {
        nodes[index].depth = depth;
        if (nodes[index].left_child != NIL)
            set_depth(nodes[index].left_child, depth + 1);
        if (nodes[index].right_child != NIL)
            set_depth(nodes[index].right_child, depth + 1);
    }

    int set_height(int index)
    {
        int h1 = 0;
        int h2 = 0;
        if (nodes[index].left_child != NIL)
            h1 = set_height(nodes[index].left_child) + 1;
        if (nodes[index].right_child != NIL)
            h2 = set_height(nodes[index].right_child) + 1;
        int h = max(h1, h2);
        nodes[index].height = h;
        return h;
    }

public:
    BinaryTree(int size)
    {
        for (int i = 0; i < size; i++)
            nodes.push_back(Node{NIL, NIL, NIL, NIL});
        setNodes(size);
        for (root = 0; root < size; root++)
        {
            if (type(root) == "root")
                break;
        }
        set_depth(root, 0);
        set_height(root);
    }

    vector<Node> getNodes() { return nodes; }
    int getRoot() { return root; }

    int sibling(int index)
    {
        int parent = nodes[index].parent;
        if (parent == NIL)
            return -1;
        else
        {
            int left = nodes[parent].left_child;
            int right = nodes[parent].right_child;
            if (left != index)
                return left;
            else
                return right;
        }
    }

    string type(int index)
    {
        if (nodes[index].parent == NIL)
            return "root";
        else if (nodes[index].left_child == NIL && nodes[index].right_child == NIL)
            return "leaf";
        else
            return "internal node";
    }

    int degree(int index)
    {
        int degree = 0;
        if (nodes[index].right_child != NIL)
            degree++;
        if (nodes[index].left_child != NIL)
            degree++;
        return degree;
    }

    void preParse(int index)
    {
        if (index != NIL)
        {
            cout << " " << index;
            preParse(nodes[index].left_child);
            preParse(nodes[index].right_child);
        }
    }

    void inParse(int index)
    {
        if (index != NIL)
        {
            inParse(nodes[index].left_child);
            cout << " " << index;
            inParse(nodes[index].right_child);
        }
    }

    void postParse(int index)
    {
        if (index != NIL)
        {
            postParse(nodes[index].left_child);
            postParse(nodes[index].right_child);
            cout << " " << index;
        }
    }
};

int main()
{
    int n;
    cin >> n;
    BinaryTree tree(n);
    int root = tree.getRoot();
    cout << "Preorder" << endl;
    tree.preParse(root);
    cout << endl;
    cout << "Inorder" << endl;
    tree.inParse(root);
    cout << endl;
    cout << "Postorder" << endl;
    tree.postParse(root);
    cout << endl;
}


Measured memory_bytes: 3164