#include <stdio.h>
#include <stdlib.h>

typedef struct P{
    int parent;
    int left;
    int right;
}Node;

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

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

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

int main(void){
    int n,i,j,k,l;
    Node *node;
    scanf("%d",&n);
    node = (Node*)malloc(sizeof(Node)*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",&k);
        scanf("%d",&l);
        node[k].left = l;
        node[l].parent = k;
        scanf("%d",&l);
        node[k].right = l;
        node[l].parent = k;
    }
    
    for(i=0;i<n;i++){
        if(node[i].parent==-1){
            k = i;
            break;
        }
    }

    printf("Preorder\n");
    pre(node,k);
    printf("\nInorder\n");
    ino(node,k);
    printf("\nPostorder\n");
    post(node,k);
    printf("\n");
    
    
}
