#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct tree{
    int left;
    int key;
    int right;
}tr[30];
void preorder(tree t,int tt);
void inorder(tree t,int tt);
void postorder(tree t,int tt);
int pre[30],ino[30],pos[30];
int j,k,l;
int main(){
    int n;
    while(~scanf("%d",&n)){
        int i;
        for(i=0;i<n;i++)
            scanf("%d %d %d",&tr[i].key,&tr[i].left,&tr[i].right);
        j=0;k=0;l=0;
        preorder(tr[0],tr[0].left);
        inorder(tr[0],tr[0].left);
        postorder(tr[0],tr[0].left);
        printf("Preorder\n");
        for(i=0;i<j;i++)
            printf("%d ",pre[i]);
        printf("\nInorder\n");
        for(i=0;i<k;i++)
            printf("%d ",ino[i]);
        printf("\nPostorder\n");
        for(i=0;i<l;i++)
            printf("%d ",pos[i]);
        printf("\n");
    }
}
void preorder(tree t,int tt){
    if(t.key!=-1){
        pre[j++]=t.key;
        if(t.left!=-1)
            preorder(tr[t.left],tr[t.left].left);
        if(t.right!=-1)
            preorder(tr[t.right],tr[t.right].right);
    }
    else return;
}
void inorder(tree t,int tt){
    if(t.key!=-1){
        if(t.left!=-1)
            inorder(tr[t.left],tr[t.left].left);
        ino[k++]=t.key;
        if(t.right!=-1)
            inorder(tr[t.right],tr[t.right].right);
    }
    else return;
}
void postorder(tree t,int tt){
    if(t.key!=-1){
        if(t.left!=-1)
            postorder(tr[t.left],tr[t.left].left);
        if(t.right!=-1)
            postorder(tr[t.right],tr[t.right].right);
        pos[l++]=t.key;
    }
    else return;
}




