#include <stdio.h>
struct TREE{
  int parent;
  int left;
  int right;
};
struct TREE tree[25];
void Preorder(int node){
  printf(" %d",node);
  if(tree[node].left!=-1)
    Preorder(tree[node].left);
   if(tree[node].right!=-1)
    Preorder(tree[node].right);
}
void Inorder (int node){
  if(tree[node].left!=-1)
    Inorder(tree[node].left);
  printf(" %d",node);
  if(tree[node].right!=-1)
    Inorder(tree[node].right); 
}
void Postorder (int node){
  if(tree[node].left!=-1)
    Postorder(tree[node].left);
  if(tree[node].right!=-1)
    Postorder(tree[node].right);
  printf(" %d",node);
}
int main(){
  int i;
  int n;
  int m,l,r;
   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",&m,&l,&r);
    tree[m].left=l;
    tree[m].right=r;
    if(l!=-1)
    tree[l].parent=m;
    if(r!=-1)
    tree[r].parent=m;
  }
  for(i=0;i<n;i++){
    if(tree[i].parent==-1)
    break;
    //printf("node%d parent%d left%d right%d\n",i,tree[i].parent,tree[i].left,tree[i].right);
  }
  
  printf("Preorder\n");
  Preorder(i);
  printf("\n");
  printf("Inorder\n");
  Inorder(i);
  printf("\n");
  printf("Postorder\n");
  Postorder(i);
  printf("\n");
  return 0;
}