// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstring>

#include<cmath>

#include<algorithm>

using namespace std;

typedef long long ll;

struct fun{

    int a;

    int b;

    int c;

}ff[30];

bool cmp(const fun &x,const fun &y){

    return x.a<y.a;

}

int f[30];

void qian(int x){

    if(x!=-1)

        printf(" %d",ff[x].a);

    else

        return ;

    qian(ff[x].b);

    qian(ff[x].c);

}

void zhong(int x){

    if(x!=-1)

        zhong(ff[x].b);

    else

        return ;

    printf(" %d",ff[x].a);

    zhong(ff[x].c);

}

void hou(int x){

    if(x!=-1)

        hou(ff[x].b);

    else

        return ;

    if(x!=-1)

        hou(ff[x].c);

    else

        return ;

    printf(" %d",ff[x].a);

}

int main(){

    int n;

    int q;

    scanf("%d",&n);

    for(int i=0;i<n;i++){

        scanf("%d%d%d",&ff[i].a,&ff[i].b,&ff[i].c);

        if(ff[i].b==-1&&ff[i].c==-1){

            f[ff[i].a]=1;

            continue;

        }

        if(ff[i].b>=0)

            f[ff[i].b]=1;

        if(ff[i].c>=0)

            f[ff[i].c]=1;

    }

    sort(ff,ff+n,cmp);

    if(n==1){

        printf("Preorder\n 0\n");

        printf("Inorder\n 0\n");

        printf("Postorder\n 0\n");

        return 0;

    }

    for(int i=0;i<n;i++)

        if(!f[i]){

            q=i;

            break;

        }

    printf("Preorder\n");

    qian(q);

    printf("\n");

    printf("Inorder\n");

    zhong(q);

    printf("\n");

    printf("Postorder\n");

    hou(q);

    printf("\n");

    return 0;

}




// Faster C++ solution for the same problem (measured speedup: 4.917515808666588x):
#include <cstdio>

#include <cstring>

#include <algorithm>

using namespace std;

struct tree{

    int left;

    int key;

    int right;

}tr[30];

bool cmp(tree t1,tree t2);

void preorder(tree t);

void inorder(tree t);

void postorder(tree t);

int pre[30],ino[30],pos[30];

int j,k,l;

int main(){

    int n;

    while(~scanf("%d",&n)){

        int i;

        memset(tr,0,sizeof(tr));

        for(i=0;i<n;i++)

            scanf("%d %d %d",&tr[i].key,&tr[i].left,&tr[i].right);

        sort(tr,tr+n,cmp);

        for(i=0;i<n;i++){

            for(j=0;j<n;j++){

                if(tr[i].key==tr[j].left||tr[i].key==tr[j].right)

                    break;

            }

            if(j==n)break;

        }

        j=0;k=0;l=0;

        preorder(tr[i]);

        inorder(tr[i]);

        postorder(tr[i]);

        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){

    if(t.key!=-1){

        pre[j++]=t.key;

        if(t.left!=-1)

            preorder(tr[t.left]);

        if(t.right!=-1)

            preorder(tr[t.right]);

    }

    else return;

}

void inorder(tree t){

    if(t.key!=-1){

        if(t.left!=-1)

            inorder(tr[t.left]);

        ino[k++]=t.key;

        if(t.right!=-1)

            inorder(tr[t.right]);

    }

    else return;

}

void postorder(tree t){

    if(t.key!=-1){

        if(t.left!=-1)

            postorder(tr[t.left]);

        if(t.right!=-1)

            postorder(tr[t.right]);

        pos[l++]=t.key;

    }

    else return;

}

bool cmp(tree t1,tree t2){

    return t1.key<t2.key;

}