#include<stdio.h>
#define MAX 10000
#define NOT -1

typedef struct {int parent,left,right;}Node;
Node T[MAX];
//int n;
//???????????????
void preParse(int u){
  if(u==NOT)return;
  printf(" %d",u);
  preParse(T[u].left);
  preParse(T[u].right);
}

//??????
void inParse(int u){
  if(u==NOT)return;
 
  inParse(T[u].left);
  printf(" %d",u);
  inParse(T[u].right);
}

//??????
void postParse(int u){
  if(u==NOT)return;
  postParse(T[u].left);
  postParse(T[u].right);
  printf(" %d",u);
}



int main(){
  int i,id,lef,righ;
  int n,root;
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    T[i].parent=NOT;
  }

  for(i=0;i<n;i++){
    scanf("%d %d %d", &id, &lef, &righ);
    T[id].left=lef;
    T[id].right=righ;
    
    if(lef!=NOT)T[lef].parent=id;
    if(righ!=NOT)T[righ].parent=id;
    
  }

  for(i=0;i<n;i++)if(T[i].parent == NOT)root=i;

  printf("Preoder\n");
  preParse(root);
  printf("\n");
  
  printf("Inorder\n");
  inParse(root);
  printf("\n");
  
  printf("Postorder\n");
  postParse(root);
  printf("\n");
  
  return 0;
}