#include <stdio.h>
#define MAX_N 30
#define NIL -1

typedef struct node_ {
    int parent;
    int left;
    int right;
} Node;

Node T[MAX_N];

void preorder(int u) {
    if (u == NIL) return;

    printf(" %d", u);
    preorder(T[u].left);
    preorder(T[u].right);
}

void inorder(int u) {
    if (u == NIL) return;

    inorder(T[u].left);
    printf(" %d", u);
    inorder(T[u].right);
}

void postorder(int u) {
    if (u == NIL) return;

    postorder(T[u].left);
    postorder(T[u].right);
    printf(" %d", u);
}

int main(void) {
    int i, n;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        T[i].parent = NIL;
        T[i].left = NIL;
        T[i].right = NIL;
    }

    for (i = 0; i < n; i++) {
        int id, left, right;
        scanf("%d %d %d", &id, &left, &right);
        T[id].left = left;
        T[id].right = right;
        if (left != NIL) T[left].parent = id;
        if (right != NIL) T[right].parent = id;
    }

    int r;
    for (i = 0; i < n; i++) {
        if (T[i].parent == NIL) r = i;
    }

    puts("Preorder");
    preorder(r); putchar('\n');
    puts("Inorder");
    inorder(r); putchar('\n');
    puts("Postorder");
    postorder(r); putchar('\n');

    return 0;
}