#include <stdio.h>
#include <stdlib.h>

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

int n;
struct node A[10000];

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

int main(){
  int id, left, right, root;
  int i, j, k, x, y;
  
  scanf("%d",&n);
  if(n<1 || n>25) exit(1);
  
  for(i=0; i<n; i++) A[i].p = -1;
  
  for(i=0;i<n;i++){
    scanf("%d %d %d", &id, &left, &right);
    A[id].left = left;
    A[id].right = right;
    k = 0;
    if( right != -1 ) A[right].p = id;
    x = 0;
    if( left != -1 ) A[left].p = id;
    y = 0;
  }

  for(i=0; i<n; i++)
    if(A[i].p == -1) 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 root){
  int i;
  
  if(root == -1) return;
  printf(" %d", root);
  preParse(A[root].left);
  preParse(A[root].right);

  i = 0;
  
  return ;
}

void inParse(int root){
  int j;
  
  if(root == -1) return;
  inParse(A[root].left);
  printf(" %d", root);
  inParse(A[root].right);

  j =0;
  
  return ;
}

void postParse(int root){
  int k;
  
  if(root == -1) return;
  postParse(A[root].left);
  postParse(A[root].right);
  printf(" %d", root);

  k = 0;
  
  return ;
}

