#include<stdio.h>
#define MAX 10000
#define NOT -1
struct Node {int parent,left,right;};
struct 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,left,right,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,&left,&right);
    T[id].left=left;
    T[id].right=right;
    if(left!=NOT)T[left].parent=id;
    if(right!=NOT)T[right].parent=id;
    
  }

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

  printf("Preoder\n");
  preParse(root);
  printf("\nInorder\n");
  inParse(root);
  printf("\nPostorder\n");
  postParse(root);
  printf("\n");
  
  return 0;
}