

#include<stdio.h>
#define N 25

typedef struct{
  int par;
  int left;
  int right;
}node;

node T[N];

void preorder(int);
void inorder(int);
void postorder(int);

int main(){
  int n,id,i;

  scanf("%d",&n);

  for(i=0;i<n;i++) T[i].par = -1;

  for(i=0;i<n;i++){

    scanf("%d",&id);
    scanf("%d %d", &T[id].left, &T[id].right);

    if(T[id].left != -1) T[T[id].left].par = id;

    if(T[id].right != -1) T[T[id].right].par = id;

  }

  for(i=0; i<n; i++){

    if(T[i].par == -1){


      printf("Preorder\n");
      preorder(i);

      printf("\nInorder\n");
      inorder(i);

      printf("\nPostorder\n");
      postorder(i);

      printf("\n");
      break;

    }
  }

  return 0;
}


void preorder(int n){
  printf(" %d",n);

  if(T[n].left != -1) preorder(T[n].left);
  if(T[n].right != -1) preorder(T[n].right);

}

void inorder(int n){
  if(T[n].left != -1) inorder(T[n].left);

  printf(" %d",n);

  if(T[n].right != -1) inorder(T[n].right);

}

void postorder(int n){

  if(T[n].left != -1) postorder(T[n].left);

  if(T[n].right != -1) postorder(T[n].right);

  printf(" %d",n);
}