#include <stdio.h>

typedef struct{
  int id;
  int left;
  int right;
  int parent;
} node;

node tree[25];

void Inorder(int);
void Preorder(int);
void Postorder(int);

int main(){

  int n,i,j,count,k,m,l,r;


  scanf("%d",&n);

  for(i=0;i<n;i++) tree[i].parent = -1;
  
  for(i=0;i<n;i++){
    scanf("%d",&m);
    tree[m].id = m;
    scanf("%d%d",&tree[m].left,&tree[m].right);
    tree[tree[m].left].parent = tree[m].id;
    tree[tree[m].right].parent = tree[m].id;
  }

  
  
  for(i=0;tree[i].parent != -1;i++);
  printf("Preorder\n");
  Preorder(i);
  printf("\n");
  printf("Inorder\n");
  Inorder(i);
  printf("\n");
  printf("Postorder\n");
  Postorder(i);
  printf("\n");
  
  return 0;
}    
    
    
void Preorder(int x){
   printf(" %d",tree[x].id);
   if(tree[x].left != -1) Preorder(tree[x].left);
   if(tree[x].right != -1) Preorder(tree[x].right);
}
void Inorder(int x){
   if(tree[x].left != -1) Inorder(tree[x].left);
   printf(" %d",tree[x].id);
   if(tree[x].right != -1) Inorder(tree[x].right);
}
void Postorder(int x){
   if(tree[x].left != -1) Postorder(tree[x].left);
   if(tree[x].right != -1) Postorder(tree[x].right);
   printf(" %d",tree[x].id);
}