#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 26
#define NIL (-1)
typedef struct {
    int parent;
    int left;
    int right;
}re;
re T[N];
int n;

void Inorder(int root);

void Postorder(int root);

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

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

    printf("Preorder\n");
    Preorder(root);
    printf("\n");

    printf("Inorder\n");
    Inorder(root);
    printf("\n");

    printf("Postorder\n");
    Postorder(root);
    printf("\n");
    return 0;
}

void Postorder(int t) {
    if(t == NIL) return ;
    Postorder(T[t].left);
    Postorder(T[t].right);
    printf(" %d", t);
}

void Inorder(int t) {
    if(t == NIL) return ;
    Inorder(T[t].left);
    printf(" %d", t);
    Inorder(T[t].right);
}
