#include <stdio.h>
#define MAX 25

struct node{
  int parent;
  int left;
  int right;
};

struct node u[MAX];

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

int main(){
  int i,n,id,left,right,root;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    u[i].parent=-1;
    u[i].left=-1;
    u[i].right=-1;
  }

  for(i=0;i<n;i++){
    scanf("%d%d%d",&id,&left,&right);
    u[id].left=left;
    u[id].right=right;
    if(left!=-1) u[left].parent=id;
    if(right!=-1) u[right].parent=id;
  }

  for(i=0;i<n;i++){
    if(u[i].parent==-1) root=i;
  }

  printf("Preorder\n");
  preParse(root);
  printf("\nInorder\n");
  inParse(root);
  printf("\nPostorder\n");
  postParse(root);
  printf("\n");

  return 0;
}

int preParse(int x){
  if(x==-1) return;
  printf(" %d",x);
  preParse(u[x].left);
  preParse(u[x].right);
}

int inParse(int x){
  if(x==-1) return;
  inParse(u[x].left);
  printf(" %d",x);
  inParse(u[x].right);
}

int postParse(int x){
  if(x==-1) return;
  postParse(u[x].left);
  postParse(u[x].right);
  printf(" %d",x);
}