#include<stdio.h>
#include<stdlib.h>
 
typedef struct{
    int p;
    int m;
    int k;
}Node;
 
void Preorder(int);
void Inorder(int);
void Postorder(int);
 
Node *node;
 
int main(void){
    int n,sd,rt;
    int i;
 
    scanf("%d",&n);
 
    node=(Node*)malloc(n*sizeof(Node));
 
    for(i=0;i<n;i++){
        node[i].p=-1;
        node[i].m=-1;
        node[i].k=-1;
    }
 
    for(i=0;i<n;i++){
        scanf("%d",&sd);
 
        scanf("%d",&node[sd].m);
        if(node[sd].m != -1) node[node[sd].m].p=sd;
 
        scanf("%d",&node[sd].k);
        if(node[sd].k != -1) node[node[sd].k].p=sd;
    }
 
    for(i=0;i<n;i++){
        if(node[i].p==-1) rt=i;
    }
 
    printf("Preorder\n");
    Preorder(rt);
    printf("\n");
 
    printf("Inorder\n");
    Inorder(rt);
    printf("\n");
 
    printf("Postorder\n");
    Postorder(rt);
    printf("\n");
 
    free(node);
 
    return 0;
}
 
void Preorder(int sd){
    printf(" %d",sd);
    if(node[sd].m != -1) Preorder(node[sd].m);
    if(node[sd].k != -1) Preorder(node[sd].k);
}
 
void Inorder(int sd){
    if(node[sd].m != -1) Inorder(node[sd].m);
    printf(" %d",sd);
    if(node[sd].k != -1) Inorder(node[sd].k);
}
 
void Postorder(int sd){
    if(node[sd].m != -1) Postorder(node[sd].m);
    if(node[sd].k != -1) Postorder(node[sd].k);
    printf(" %d",sd);
}

