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

typedef struct{
  int parent,left,right;
}family;
family t[MAX];

void preParse(int);
void inParse(int);
void postParse(int);

int main(){
  int i,id,lef,rig,root,n;
  scanf("%d",&n);
  for(i = 0;i < n;i++) t[i].parent = NIL;

  for(i = 0;i < n;i++){
    scanf("%d%d%d",&id,&lef,&rig);
    t[id].left = lef;
    t[id].right = rig;
    if(lef != NIL) t[lef].parent = id;
    if(rig != NIL) t[rig].parent = id;
  }
  for(i = 0;i < n;i++) if(t[i].parent == NIL) root = i;

  printf("Preorder\n");
  preParse(root);
  printf("\n");
  printf("Inorder\n");
  inParse(root);
  printf("\n");
  printf("Postorder\n");
  postParse(root);
  printf("\n");
  return 0;
}

void preParse(int u){
  if(u == NIL) return;
  printf(" ");
  printf("%d",u);
  preParse(t[u].left);
  preParse(t[u].right);
}

void inParse(int u){
  if(u == NIL) return;
  inParse(t[u].left);
  printf(" ");
  printf("%d",u);
  inParse(t[u].right);
}

void postParse(int u){
  if(u == NIL) return;
  postParse(t[u].left);
  postParse(t[u].right);
  printf(" ");
  printf("%d",u);
}

