//tree walk

#include<stdio.h>
#define N 10000

struct Node
{
  int p,l,r;
};

struct Node tree[N];
int n;

void pre(int x)
{
  if(x == -1) return;
  printf(" %d",x);
  pre(tree[x].l);
  pre(tree[x].r);
}

void in(int x)
{
  if(x == -1) return;
  in(tree[x].l);
  printf(" %d",x);
  in(tree[x].r);
}

void post(int x)
{
  if(x == -1) return;
  post(tree[x].l);
  post(tree[x].r);
  printf(" %d",x);
}

int main()
{
  int i,pa,le,ri,root;
  
  //input & initialize number
  scanf("%d",&n);
  for(i = 0; i < n; i++) tree[i].p = -1;

  for(i = 0; i < n; i++)
    {
      scanf("%d %d %d",&pa,&le,&ri);
      tree[pa].l = le;
      tree[pa].r = ri;
      if(le != -1) tree[le].p = pa;
      if(ri != -1) tree[ri].p = pa;
    }

  for(i = 0;i < n; i++)
    {
      if(tree[i].p == -1) root = i;
    }

  printf("Preorder\n");
  pre(root);
  printf("\n");
  printf("Inorder\n");
  in(root);
  printf("\n");
  printf("Postorder\n");
  post(root);
  printf("\n");

  return 0;
}

