#include <stdio.h>
#include <stdlib.h>
struct node {
    int parent;
    int left; int right;
};

void preorder(struct node T[], int u);
void inorder(struct node T[], int u);
void postorder(struct node T[], int u);

int main(void) {
    int n, i, k;
    scanf("%d", &n);
    struct node *T;
    T = malloc(sizeof(struct node) * n);
    for (k = 0; k < n; k++) {
        scanf("%d", &i);
        scanf("%d %d", &((T + i)->left), &((T + i)->right));
    }

    printf("Preorder\n");
    preorder(T, 0);
    printf("\nInorder\n");
    inorder(T, 0);
    printf("\nPostorder\n");
    postorder(T, 0);
    printf("\n");
    free(T);

    return 0;
}

void preorder(struct node T[], int u) {
    if (u == -1) return;
    printf("%d ", u);
    preorder(T, T[u].left);
    preorder(T, T[u].right);
}
void inorder(struct node T[], int u) {
    if (u == -1) return;
    inorder(T, T[u].left);
    printf("%d ", u);
    inorder(T, T[u].right);
}
void postorder(struct node T[], int u) {
    if (u == -1) return;
    postorder(T, T[u].left);
    postorder(T, T[u].right);
    printf("%d ", u);
}