#include<stdio.h>
#define MAX 200000

typedef struct{
    int parent;
    int left;
    int right;
}gNode;

int r_search();
void Inorder(int);
void Preorder(int);
void Postorder(int);

int n;
gNode Node[MAX];

int main(){
    int i;
    int id, left, right, root;

    scanf("%d", &n);
    for(i = 0 ; i < n ; i++){
        Node[i].parent = -1;
        Node[i].left = -1;
        Node[i].right = -1;
    }

    for(i = 0 ; i < n ; i++){
        scanf("%d%d%d", &id, &left, &right);
        Node[id].left = left;
        Node[id].right = right;

        //親の設定
        if(left != -1)Node[left].parent = id;
        if(right != -1) Node[right].parent = id;
    }

    //rootを調べんで〜
    root = r_search();

    printf("Preorder\n");
    Preorder(root);
    printf("\n");
    printf("Inorder\n");
    Inorder(root);
    printf("\n");
    printf("Postorder\n");
    Postorder(root);
    printf("\n");

    return 0;
}

int r_search(){
    for(int i = 0 ; i < n ; i++){
        if(Node[i].parent == -1) return i;
    }
    return 0;
}

void Inorder(int id){
    if(id == -1) return;
    Inorder(Node[id].left);
    printf(" %d", id);
    Inorder(Node[id].right);
}

void Preorder(int id){
    if(id == -1) return;
    printf(" %d", id);
    Preorder(Node[id].left);
    Preorder(Node[id].right);
}

void Postorder(int id){
    if(id == -1) return;
    Postorder(Node[id].left);
    Postorder(Node[id].right);
    printf(" %d", id);
}

