#include <stdio.h>
#define N 25
 
void Defpre(int);

void Defin(int);

void Defpost(int);
 
typedef struct node{int nump,numl,numr;}Node;

Node array[N];

int n;
 
int main(){
  int i,numl,numr,nump;

int root,numv;
 
  scanf("%d",&n);
  for(i = 0;i < n;i++){
    array[i].nump = -1;
  }
  for(i = 0;i < n;i++){
    scanf("%d%d%d",&numv,&numl,&numr);

    array[numv].numl = numl;

    array[numv].numr = numr;

    if(numl != -1) array[numl].nump = numv;

    if(numr != -1) array[numr].nump = numv;
  }
 
  for(i = 0;i < n;i++){
    if(array[i].nump == -1) 
      root = i;
  }
 
  printf("Preorder\n");
  
Defpre(root);

  printf("\n");

  printf("Inorder\n");

  Defin(root);

  printf("\n");

  printf("Postorder\n");

  Defpost(root);

  printf("\n");
 
  return 0;
}
 
void Defpre(int num){
  if(num == -1) {
    return;
  }
  printf(" %d",num);

  Defpre(array[num].numl);

  Defpre(array[num].numr);
}
 
void Defin(int num){
  if(num == -1) {
    return;
  }
  Defin(array[num].numl);
  
printf(" %d",num);

  Defin(array[num].numr);
}
 
void Defpost(int num){
  if(num == -1){
    return;
  }
  Defpost(array[num].numl);

  Defpost(array[num].numr);

  printf(" %d",num);
}