#include <stdio.h>
#define NIL -1
void echoPre(int );
void echoIn(int );
void echoPost(int );
typedef struct{
  int left,right,parent;
}Tree;
Tree Node[26];
int n;
int main(void){
  int i,j,migi,hidari,oya,node;
  scanf("%d",&n);
  i=0;
  while(i<n){
    Node[i].left=NIL;
    Node[i].right=NIL;
    Node[i].parent=NIL;
    i++;
  }

  i=0;
  while(i<n){
    // initial setting
    scanf("%d%d%d",&node,&hidari,&migi);
    if(hidari!=NIL)
      Node[hidari].parent=node;
    if(migi!=NIL)
      Node[migi].parent=node;
    Node[node].left=hidari;
    Node[node].right=migi;
    i++;
  }

  //search for node of root
  i=-1;
  while(++i<n)
    if(Node[i].parent==NIL)
      j=i;

  printf("Preorder\n");
  echoPre(j);
  printf("\nInorder\n");
  echoIn(j);
  printf("\nPostorder\n");
  echoPost(j);
  printf("\n");
  return 0;
}
void echoPre(int node){
  printf(" %d",node);
  if(Node[node].left!=NIL)
    echoPre(Node[node].left);
  if(Node[node].right!=NIL)
    echoPre(Node[node].right);
}
void echoIn(int node){
  if(Node[node].left!=NIL)
    echoIn(Node[node].left);
  printf(" %d",node);
  if(Node[node].right!=NIL)
    echoIn(Node[node].right);
}
void echoPost(int node){
  if(Node[node].left!=NIL)
    echoPost(Node[node].left);
  if(Node[node].right!=NIL)
    echoPost(Node[node].right);
  printf(" %d",node);
}
