#include <stdio.h>

struct node {
    int value;
    int left;
    int right;
};

struct node tree[1000000];
int n;

void Preorder(int now)
{   
    static int first = 0;
    if(first==0) printf("Preorder\n");
    first = 1;

    if(now == -1){
        return;
    }

    printf(" %d", now);
    Preorder(tree[now].left);
    Preorder(tree[now].right);

}

void Inorder(int now)
{   
    static int first = 0;
    if(first==0) printf("Inorder\n");
    first = 1;

    if (now == -1){
        return;
    }

    Inorder(tree[now].left);
    printf(" %d", now);
    Inorder(tree[now].right);

}

void Postorder(int now)
{   
    static int first = 0;
    if(first==0) printf("Postorder\n");
    first = 1;

    if(now == -1){
        return;
    }

    Postorder(tree[now].left);
    Postorder(tree[now].right);
    printf(" %d", now);

}

int main()
{
    int i;
    int value,left,right;
    int root;

    scanf("%d",&n);
    for(i=0;i<n;i++) tree[i].value = -1;

    for(i=0;i<n;i++){
        scanf("%d %d %d",&value,&left,&right);
        tree[value].left=left;
        tree[value].right=right;
        if(left!=-1) tree[left].value = value;
        if (right!=-1) tree[right].value = value;
    }
    
    for(i=0;i<n;i++){
        if(tree[i].value == -1) root = i;
    }

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

    return (0);
}
