#include<stdio.h>
#define N 10000
typedef struct{
  int p;
  int left;
  int right;
}Node;
Node tary[N];
int n;

void pre(int value){
  if(value==-1)return;
  printf(" %d",value);
  pre(tary[value].left);
  pre(tary[value].right);
}

void in(int value){
  if(value==-1)return;
  in(tary[value].left);
  printf(" %d",value);
  in(tary[value].right);
}
void post(int value){
  if(value==-1)return;
  post(tary[value].left);
  post(tary[value].right);
  printf(" %d",value);
}
int main(){
  int i,v,left,right,r;
  scanf("%d",&n);
  for(i=0;i<n;i++){tary[i].p=-1;}

  for(i=0;i<n;i++){
    scanf("%d%d%d",&v,&left,&right);
    tary[v].left=left;
    tary[v].right=right;
    if(left!=-1)tary[left].p=v;
    if(right!=-1)tary[right].p=v;
  }
  for(i=0;i<n;i++){
    if(tary[i].p==-1)r=i;
  }
  printf("Preorder\n");
  pre(r);
  printf("\n");
  printf("Inorder\n");
  in(r);
  printf("\n");
  printf("Postorder\n");
  post(r);
  printf("\n");
  return 0;
}
    

