#include <stdio.h>
#include <stdlib.h>

#define NIL -1

typedef struct {
    int left, right;
} Node;

int n;
Node *tree;

void preOrderPrint(int index) {
    printf("%d", index);
    if (tree[index].left != NIL) {
        printf(" ");
        preOrderPrint(tree[index].left);
    }
    if (tree[index].right != NIL) {
        printf(" ");
        preOrderPrint(tree[index].right);
    }
}

void inOrderPrint(int index) {
    if (tree[index].left != NIL) {
        inOrderPrint(tree[index].left);
        printf(" ");
    }
    printf("%d", index);
    if (tree[index].right != NIL) {
        printf(" ");
        inOrderPrint(tree[index].right);
    }
}

void postOrderPrint(int index) {
    if (tree[index].left != NIL) {
        postOrderPrint(tree[index].left);
        printf(" ");
    }
    if (tree[index].right != NIL) {
        postOrderPrint(tree[index].right);
        printf(" ");
    }
    printf("%d", index);
}

int main() {
    scanf("%d", &n);

    tree = malloc(sizeof(Node) * n + 1);

    int index, left, right;
    for (int i = 0; i < n; i++) {
        scanf("%d %d %d", &index, &left, &right);
        tree[index].left = left;
        tree[index].right = right;
    }

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

    printf("\nInorder\n");
    inOrderPrint(0);

    printf("\nPostorder\n");
    postOrderPrint(0);
    printf("\n");

    return 0;
}

