#include<stdio.h>
#define N 25

typedef struct{

  int parent;
  int left;
  int right;

}Node;

int n;
Node in[N];

void init();
void PreOrder(Node *, int);
void InOrder(Node *, int);
void PostOrder(Node *, int);


int main(){

  int i,id;

  init();

  scanf("%d\n",&n);

  for(i = 0; i < n; i++){
    scanf("%d",&id);
    scanf("%d %d", &in[id].left, &in[id].right);

    if(in[id].left == -1 && in[id].right == -1){
      continue;
    }

    in[in[id].left].parent == id;
    in[in[id].right].parent == id;

  }

    printf("Preorder\n");
    PreOrder(in, 0);
    printf("\n");

    printf("Inorder\n");
    InOrder(in, 0);
    printf("\n");

    printf("Postorder\n");
    PostOrder(in, 0);
    printf("\n");
 
  return 0;

}


void init(){
  int i;

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

}


void PreOrder(Node *preA, int num){

  printf(" %d",num);
  
  if(preA[num].left != -1){
    PreOrder(preA, preA[num].left);
  }

  if(preA[num].right != -1){
    PreOrder(preA, preA[num].right);
  }

}


void InOrder(Node *inA, int num){
 
 if(inA[num].left != -1){
    InOrder(inA, inA[num].left);
  }

  printf(" %d",num);
  
  if(inA[num].right != -1){
    InOrder(inA, inA[num].right);
  }

}


void PostOrder(Node *postA, int num){
  
  if(postA[num].left != -1){
    PostOrder(postA ,postA[num].left);
  }

  if(postA[num].right != -1){
    PostOrder(postA, postA[num].right);
  }

  printf(" %d",num);

}