#include<stdio.h>
#define MAX 25
#define NIL -1
struct tree {
        int parent;
        int left;
        int right;
};
void dispf(int, struct tree*);
void dispm(int, struct tree*);
void dispb(int, struct tree*);
main()
{
        struct tree t[MAX];
        int i, j, n, id, l, r, prec, root;
        scanf("%d", &n);
        for (i = 0; i < n; i++) {
                t[i].parent = NIL;
        }
    for(i = 0; i < n; i++) {
        scanf("%d %d %d", &id, &l, &r);
        t[id].left = l;
                t[id].right = r;
                if (l != -1) {
                        t[l].parent = id;
                }
                if (r != -1) {
                        t[r].parent = id;
                }
    }
    for (i = 0; i < n; i++) {
        if(t[i].parent == NIL) {
                        root = i;
                        break;
                }
        }
        printf("Preorder\n");
        dispf(root, t);
        printf("\nInorder\n");
        dispm(root, t);
        printf("\nPostorder\n");
        dispb(root, t);
        putchar('\n');
}
void dispf(int u, struct tree *t)
{
        if (u == NIL) {
                return;
        } else {
                printf(" %d", u);
                dispf(t[u].left, t);
                dispf(t[u].right, t);
        }
}
void dispm(int u, struct tree *t)
{
    if (u == NIL) {
        return;
    } else {
        dispm(t[u].left, t);
                printf(" %d", u);
        dispm(t[u].right, t);
    }
}
void dispb(int u, struct tree *t)
{
    if (u == NIL) {
        return;
    } else {
        dispb(t[u].left, t);
        dispb(t[u].right, t);
                printf(" %d", u);
    }
}