#include<stdio.h>
#define NIL -1

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


typedef struct{
  int parent;
  int left;
  int right;
}vertex;

int D[25],n;
int ver[25];
vertex Tree[25];

int main(){
  
  int i,l,r;
  
  scanf("%d",&n);
  
  for( i=0 ; i<n ; i++){
    Tree[i].parent = Tree[i].left = Tree[i].right = NIL;
  }
  for( i=0 ; i<n ; i++){
    scanf("%d",&ver[i]);
    
    if(i == 0){
      Tree[ ver[i] ] .parent= NIL;
    }

    scanf("%d",&Tree[ver[i]].left);
    scanf("%d",&Tree[ver[i]].right);
    
    l = Tree[ver[i]].left;
    r = Tree[ver[i]].right;
    Tree[l].parent = Tree[r].parent = ver[i];
  }

  for( i=0 ; i<n ; i++){
    Preorder(i);
    Inorder(i);
    Postorder(i);
  }
 
  return 0;
}

void Preorder(int i){

  printf("Preorder\n");
  printf(" %d",Tree[i].right);
  if(Tree[i].left != NIL) Preorder(Tree[i].left);
    if(Tree[i].right != NIL) Preorder(Tree[i].right);
}

void Inorder(int i){

  printf("Inorder\n");
    if(Tree[i].left != NIL) Inorder(Tree[i].left);
    printf(" %d", Tree[i].right);
    if(Tree[i].right != NIL) Inorder(Tree[i].right);
}  

void Postorder(int i);

  printf("postorder\n");
 if(Tree[i].left != NIL) Postorder(Tree[i].left);
    if(Tree[i].right != NIL) Postorder(Tree[i].right);
    printf(" %d", Tree[i].right);
}