#include <stdio.h>
#include <vector>
#include <list>
#include <map>
#include <array>
#include <memory>
#include <string>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <unordered_map>
#include <stdexcept>


using std::string;
using std::vector;


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// util
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

std::vector<std::string> split(const std::string& input, char delimiter)
{
    std::istringstream stream(input);

    std::string field;
    std::vector<std::string> result;
    while (std::getline(stream, field, delimiter)) {
        result.push_back(field);
    }
    return result;
}



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// user func
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void printList(const vector<int>& list) {
    // print
    for(int i = 0; i < list.size(); i++){
        printf("%d", list[i]);
        if(i != list.size() -1){
            printf(" ");
        }
    }
    printf("\n");
}



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// logic
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class Node;
using Container = std::map<int, std::shared_ptr<Node>>;
class Node{
private:
    Container *container;
    int id;
    int left;
    int right;
    int parentId;
public:
    Node(Container* container, int id, int left, int right)
        : container(container)
        , id(id)
        , left(left)
        , right(right)
        , parentId(-1)
    {
    }

    int Id(){
        return this->id;
    }
    int Left(){
        return this->left;
    }
    int Right(){
        return this->right;
    }

    void ParentId(int id){
        this->parentId = id;
    }

    int ParentId(){
        return this->parentId;
    }

    int Sibling(){
        // root
        if (this->parentId == -1) return -1;
        if (this->Parent()->Left() == this->id) {
            return this->Parent()->Right();
        } else {
            return this->Parent()->Left();
        }
    }

    int Degree(){
        int result = this->left == -1 ? 0 : 1;
        result   += this->right == -1 ? 0 : 1;
        return result;
    }

    int Depth(){
        if(this->parentId == -1){
            return 0;
        }else{
            return this->Parent()->Depth() + 1;
        }
    }

    int Height(){
        if(this->left + this->right == -2) return 0;
        int lHeight = this->left == -1 ? 0 : (*this->container)[this->left]->Height();
        int rHeight = this->right == -1 ? 0 : (*this->container)[this->right]->Height();
        return std::max(lHeight, rHeight) + 1;
    }

    string Type(){
        if(this->parentId == -1)
        {
            return "root";
        }
        if(this->left + this->right == -2)
        {
            return "leaf";
        }
        else
        {
            return "internal node";
        }
    }

    std::shared_ptr<Node> Parent(){
        if(this->parentId == -1) return nullptr;
        return (*this->container)[this->parentId];
    }
    bool HasLeft(){
        return this->left != -1;
    }
    bool HasRight(){
        return this->right != -1;
    }
    
};

void Preorder(const Container& container, int id){
    auto cur = container.at(id);
    printf(" %d", cur->Id());
    if (cur->HasLeft()) Preorder(container, cur->Left());
    if (cur->HasRight()) Preorder(container, cur->Right());
}


void Inorder(const Container& container, int id){
    auto cur = container.at(id);
    if(!cur->HasLeft() && !cur->HasRight()){
        printf(" %d", cur->Id());
        return;
    }
    if (cur->HasLeft()) Inorder(container, cur->Left());
    printf(" %d", cur->Id());
    if (cur->HasRight()) Inorder(container, cur->Right());
}

void Postorder(const Container& container, int id){
    auto cur = container.at(id);
    if(!cur->HasLeft() && !cur->HasRight()){
        printf(" %d", cur->Id());
        return;
    }
    if (cur->HasLeft()) Postorder(container, cur->Left());
    if (cur->HasRight()) Postorder(container, cur->Right());
    printf(" %d", cur->Id());

}
int FindRoot(const Container& container){
    for(auto each: container){
        if(each.second->ParentId() == -1){
            return each.first;
        }
    }
    return -1;
}

void solve() {
    // binary trees
    int n;
    scanf("%d", &n);
    Container container;
    for(int i = 0; i < n; i++){
        int id;
        int left, right;
        scanf("%d %d %d", &id, &left, &right);
        auto node = std::make_shared<Node>(&container, id, left, right);
        container.insert(std::make_pair(id, node));
    }
    // set parent
    for(auto& each: container){
        if(each.second->Left() != -1){
            container[each.second->Left()]->ParentId(each.second->Id());
        }
        if(each.second->Right() != -1){
            container[each.second->Right()]->ParentId(each.second->Id());
        }
    }
    int rootId = FindRoot(container);
    printf("Preorder\n");
    Preorder(container, rootId);
    printf("\n");

    printf("Inorder\n");
    Inorder(container, rootId);
    printf("\n");

    printf("Postorder\n");
    Postorder(container, rootId);
    printf("\n");

    
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// main
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main() {
    solve();
    return 0;
}


Measured memory_bytes: 3212