#include<stdio.h>
#define MAX 10000

typedef struct{
    int p,left,right;
}point;
int n;
point t[MAX];
void pre(int x){
    if(x==-1)return;
    printf(" %d",x);
    pre(t[x].left);
    pre(t[x].right);
}
void in(int x){
    if(x==-1)return;
    in(t[x].left);
    printf(" %d",x);
    in(t[x].right);
}
void post(int x){
    if(x==-1)return;
    post(t[x].left);
    post(t[x].right);
    printf(" %d",x);
}
int main(){
    int i,left,right,root,x;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        t[i].p=-1;
    }
    for(i=0;i<n;i++){
        scanf("%d %d %d",&x,&left,&right);
        t[x].right=right;
        t[x].left=left;
        if(right!=-1)t[right].p=x;
        if(left!=-1)t[left].p=x;
    }
    for(i=0;i<n;i++){
        if(t[i].p==-1)root=i;
    }
    printf("Preorder\n");
    pre(root);
    printf("\n");
    printf("Inorder\n");
    in(root);
    printf("\n");
    printf("Postorder\n");
    post(root);
    printf("\n");
    return 0;
}
