#include <stdio.h>

int p[100000],l[100000],r[100000],d[100000],h[100000],root;

void depth(int x,int dep){
  d[x]=dep;
  if(r[x]!= -1)depth(r[x],dep+1);
  if(l[x]!= -1)depth(l[x],dep+1);
}

int height(int x){
  int h1=0,h2=0;

  if(l[x]!=-1)h1=height(l[x])+1;
  if(r[x]!=-1)h2=height(r[x])+1;

  if(h1>h2){
    h[x]=h1;
    return h1;
  }
  else{
    h[x]=h2;
    return h2;
  }
}

void pre(int x){
  if(x==-1)return;

  printf(" %d",x);
  pre(l[x]);
  pre(r[x]);
}

void in(int x){
  if(x==-1)return;

  in(l[x]);
  printf(" %d",x);
  in(r[x]);
}

void post(int x){
  if(x==-1)return;

  post(l[x]);
  post(r[x]);
  printf(" %d",x);
}

int main(){
  int i,j,n,t,t1,t2,t3;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    p[i]=-1;
    l[i]=-1;
    r[i]=-1;
  }
  for(i=0;i<n;i++){
    scanf("%d%d%d",&t1,&t2,&t3);
    l[t1]=t2;
    r[t1]=t3;
    if(t2!=-1)p[t2]=t1;
    if(t3!=-1)p[t3]=t1;
  }

  for(i=0;i<n;i++){
    if(p[i]==-1){
      root=i;
      break;
    }
  }
  depth(root,0);
  height(root);

  printf("Preorder\n");
  pre(root);
  printf("\nInorder\n");
  in(root);
  printf("\nPostorder\n");
  post(root);
  printf("\n");

  return 0;
}

