#include <iostream>
#include <sstream>
#include <vector>

struct Node{
    int id;
    int left;
    int right;

    int parent;
    int sibling;
    int degree;
    int depth;
    int height;
};

std::string get_type(Node& node){
    if(node.parent == -1) return "root";
    if(node.right >= 0 || node.left >= 0) return "internal node";
    return "leaf";
}

void to_str(std::stringstream& ss, Node& n){
    ss << "node " << n.id << ": ";
    ss << "parent = " << n.parent << ", ";
    ss << "sibling = " << n.sibling << ", ";
    ss << "degree = " << n.degree << ", ";
    ss << "depth = " << n.depth << ", ";
    ss << "height = " << n.height << ", ";
    //ss << "left = " << n.left << ", ";
    //ss << "right = " << n.right << ", ";
    ss << get_type(n) << std::endl;
}

int trace_depth(std::vector<Node>& nodes, Node& node){
    if(node.depth >= 0){
        ; // pass
    }else if(node.parent == -1){
        node.depth = 0;
        return 0;
    }else{
        int p = trace_depth(nodes, nodes[node.parent]);
        node.depth = p + 1;
    }
    return node.depth;
}

int trace_height(std::vector<Node>& nodes, Node& node){
    if(node.height >= 0){
        ; // pass
    }else if(node.left == -1 && node.right == -1){
        node.height = 0;
    }else{
        int ld = -1, rd = -1;
        ld = node.left >= 0 ? trace_height(nodes, nodes[node.left]) : -1;
        rd = node.right >= 0 ? trace_height(nodes, nodes[node.right]) : -1;
        node.height = ld > rd ? ld + 1 : rd + 1;
    }
    return node.height;
}

void trace_preorder(std::vector<int>& lst, std::vector<Node>& nodes, int id){
    lst.push_back(id);
    if(nodes[id].left >= 0)
        trace_preorder(lst, nodes, nodes[id].left);
    if(nodes[id].right >= 0)
        trace_preorder(lst, nodes, nodes[id].right);
}
void trace_inorder(std::vector<int>& lst, std::vector<Node>& nodes, int id){
    if(nodes[id].left >= 0)
        trace_inorder(lst, nodes, nodes[id].left);
    lst.push_back(id);
    if(nodes[id].right >= 0)
        trace_inorder(lst, nodes, nodes[id].right);
}
void trace_postorder(std::vector<int>& lst, std::vector<Node>& nodes, int id){
    if(nodes[id].left >= 0)
        trace_postorder(lst, nodes, nodes[id].left);
    if(nodes[id].right >= 0)
        trace_postorder(lst, nodes, nodes[id].right);
    lst.push_back(id);
}

int main(int argc, char **argv){
    int N;
    std::cin >> N;

    std::vector<Node> nodes(N);
    
    for(int i = 0; i < N; i++){
        int id, l, r;
        std::cin >> id >> l >> r;
        nodes[id].id = id;
        nodes[id].left = l;
        nodes[id].right = r;
        nodes[id].parent = -1;
        nodes[id].sibling = -1;
        nodes[id].degree = -1;
        nodes[id].depth = -1;
        nodes[id].height = -1;
    }
   
    for(int i = 0; i < N; i++){
        int d = 0;
        if(nodes[i].left >= 0){
            nodes[nodes[i].left].parent = nodes[i].id;
            d++;
        }
        if(nodes[i].right >= 0){
            nodes[nodes[i].right].parent = nodes[i].id;
            d++;
        }
        nodes[i].degree = d;      
    }

    int root_id = -1;
    for(int i = 0; i < N; i++){
        if(nodes[i].parent == -1)
            root_id = i;
    }
    
    int max_depth = -1;
    for(int i = 0; i < N; i++){
        if(nodes[i].parent >= 0){
            if(nodes[nodes[i].parent].left != i){
                nodes[i].sibling = nodes[nodes[i].parent].left;
            }else{
                nodes[i].sibling = nodes[nodes[i].parent].right;
            }
        }
        trace_depth(nodes, nodes[i]);
        trace_height(nodes, nodes[i]);
    }
    /*
    std::stringstream ss;
    for(auto& n: nodes){
        to_str(ss, n);
    }
    std::cout << ss.str();
    */

    {
        std::stringstream ss;
        std::cout << "Preorder" << std::endl;
        std::vector<int> lst;
        trace_preorder(lst, nodes, root_id);
        for(int v : lst){
            ss << " " << v;
        }
        std::cout << ss.str() << std::endl;
    }
    
    {  
        std::stringstream ss;
        std::cout << "Inorder" << std::endl;
        std::vector<int> lst;
        trace_inorder(lst, nodes, root_id);
        for(int v : lst){
            ss << " " << v;
        }
        std::cout << ss.str() << std::endl;
    }
    
    {
        std::stringstream ss;
        std::cout << "Postorder" << std::endl;
        std::vector<int> lst;
        trace_postorder(lst, nodes, root_id);
        for(int v : lst){
            ss << " " << v;
        }
        std::cout << ss.str() << std::endl;
    }    
}



Measured memory_bytes: 3216