#include <stdio.h>
struct Node {int num, left, right; };
struct Node T[10000];
void pre(int a);
void in(int a);
void post(int a);

int main(void)
{
    int n, i, v, l, r, root;
    scanf("%d",&n);
    for(i = 0; i < n; i++)
    {
        T[i].num = -1;
    }
    for(i = 0; i < n; i++)
    {
        scanf("%d %d %d",&v, &l, &r);
        T[v].left = l;
        T[v].right = r;
        if(l != -1) T[l].num = v;
        if(r != -1) T[r].num = v;
    }
    for(i = 0; i < n; i++)
    {
        if(T[i].num == -1) root = i;
    }
    printf("Preorder\n");
    pre(root);
    printf("\nInorder\n");
    in(root);
    printf("\nPostorder\n");
    post(root);
    printf("\n");
    return 0;
}
void pre(int a)
{
    if(a == -1) return;
    
    printf(" %d",a);
    pre(T[a].left);
    pre(T[a].right);
}
void in(int a)
{
    if(a == -1) return;
    in(T[a].left);
    printf(" %d",a);
    in(T[a].right);
}
void post(int a)
{
    if(a == -1) return;
    post(T[a].left);
    post(T[a].right);
    printf(" %d",a);
}
