#include <stdio.h>
#define N_MAX 26

typedef struct T{
  int parent;
  int left;
  int right;
}TREE;

TREE tree[N_MAX];

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

int main(){
  int i,n,id,lef,rig;
  
  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 %d %d",&id,&lef,&rig);
    tree[id].left = lef;
    tree[id].right = rig;
    
    if(lef!=-1)
      tree[lef].parent = id;
    if(rig!=-1)
      tree[rig].parent = id;
  }
  for(i=0;i<n;i++){
    if(tree[i].parent==-1)
      break;
  }
  
  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 vat){
  printf(" %d",vat);
  if(tree[vat].left!=-1)
    Preorder(tree[vat].left);
  if(tree[vat].right!=-1)
    Preorder(tree[vat].right);
}
void Inorder (int vat){
  if(tree[vat].left!=-1)
    Inorder(tree[vat].left);
  printf(" %d",vat);
  if(tree[vat].right!=-1)
    Inorder(tree[vat].right); 
}
void Postorder (int vat){
  if(tree[vat].left!=-1)
    Postorder(tree[vat].left);
  if(tree[vat].right!=-1)
    Postorder(tree[vat].right);
  printf(" %d",vat);
}

