#include <stdio.h>
#define MAX 10000

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

struct Node{
  int parent, left, right;
};
 
struct Node Tree[MAX];
int n;

void Preorder(int i){
  printf(" %d",i);
  if ( Tree[i].left != -1 ) Preorder( Tree[i].left );
  if ( Tree[i].right != -1 ) Preorder( Tree[i].right );
}

void Inorder(int i){
  if( Tree[i].left != -1 ) Inorder( Tree[i].left );
  printf(" %d",i);
  if( Tree[i].right != -1 ) Inorder( Tree[i].right);
}
  
void Postorder(int i){ 
  if( Tree[i].left != -1 ) Postorder( Tree[i].left );
  if( Tree[i].right != -1 ) Postorder( Tree[i].right );
  printf(" %d",i);
  
}

int main(){
  int v,l,r,root = 0,i,deg,j,c;
  scanf("%d",&n);
 
  for( i = 0 ; i < n ; i++ ){
    Tree[i].parent = -1;
    Tree[i].left = -1;
    Tree[i].right = -1;
  }

  for( i = 0 ; i < n ; i++ ){
    scanf("%d",&v);
    for( j = 0 ; j < 2 ; j++ ){
      scanf("%d",&c); 
      if ( j == 0 ) Tree[v].left = c;  
      else Tree[v].right = c;
      Tree[c].parent = v;       
    }
  }

  printf("Preorder\n");
  for( i = 0 ; i < n ; i++ ){
    if( Tree[i].parent == -1 ) {
      root = i;
      break;
    }
  }

  printf("Preorder\n");
  Preorder(root);

  printf("Inorder\n");
  Inorder(root);

  printf("Postorder\n");
  Postorder(root);
  printf("\n");

  return 0;
}