#include<stdio.h>
#define MAX 10000
#define null -1

struct node { int p, l, r; };
struct node t[MAX];
int n;

void prePause(int u){
    if (u == null)
        return;
    printf(" %d", u);
    prePause(t[u].l);
    prePause(t[u].r);
}

void inPause(int u){
    if ( u == null)
        return;
    inPause(t[u].l);
    printf(" %d", u);
    inPause(t[u].r);
}

void postPause(int u){
    if (u == null)
        return;
    postPause(t[u].l);
    postPause(t[u].r);
    printf(" %d", u);
}

int main(){
    int i, v, l, r, root;
    
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        t[i].p = null;
    }
    
    for(i = 0; i < n; i++){
        scanf("%d %d %d", &v, &l, &r);
        t[v].l = l;
        t[v].r = r;
        if (l != null)
            t[l].p = v;
        if (r != null)
            t[r].p = v;
    }
    
    for (i = 0; i < n; i++){
        if (t[i].p == null)
            root = i;
    }         
    
    printf("Preorder\n");
    prePause(root);
    putchar('\n');
    printf("Inorder\n");
    inPause(root);
    putchar('\n');
    printf("Postorder\n");
    postPause(root);
    putchar('\n');
    
    return 0;
}
