#include <stdio.h>
#include <stdlib.h>

typedef struct{
  int p;
  int l;
  int r;
}Tree;

int n;
Tree tree[25];

void inorder(int a){
 
  if(tree[a].l != -1)inorder(tree[a].l);
  
  printf(" %d",a);

  if(tree[a].r != -1)inorder(tree[a].r);
   
}

  
void preorder(int a){
 
  printf(" %d",a);
  
  if(tree[a].l != -1)preorder(tree[a].l);

  if(tree[a].r != -1)preorder(tree[a].r);

}

void postorder(int a){
  
  if(tree[a].l != -1)postorder(tree[a].l);

  if(tree[a].r != -1)postorder(tree[a].r);

  printf(" %d",a);
 
}

int main(){
  
  int i,id,parent;

  scanf("%d",&n);
  
   for(i = 0; i < n; i++){
     tree[i].p = -1;
   }
  
  for(i = 0; i < n; i++){
    scanf("%d",&id);
    scanf("%d%d",&tree[id].l,&tree[id].r);
    if(tree[id].l != -1)tree[tree[id].l].p = id;
    if(tree[id].r != -1)tree[tree[id].r].p = id;
   }
  
  for(i = 0; i < n; i++){
    if(tree[i].p == -1){
      parent = i;
      break;
    }
  }
  
  printf("Preorder\n");
  preorder(parent);
  printf("\n");
  
  printf("Inorder\n");
  inorder(parent);
  printf("\n");
  
  printf("Postorder\n");
  postorder(parent);
  printf("\n");
  
  return 0;
}

