#include<stdio.h>
#include<stdlib.h>
#define N 25

struct Node{
  int left,right;
  int parent;
  int id;
};
struct Node T[N];
int P[N],I[N],Po[N];
int pre=0,in=0,post=0;
int n;

void presort(int);
void insort(int);
void postsort(int);

int main(void){

  scanf("%d",&n);
 
  int i,j;
  for(i=0;i<n;i++){
    T[i].parent = -1;
  }

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

  for(i=0;i<n;i++){
    int R = T[i].right;
    int L = T[i].left;
    if(R != -1)  {
      for(j=0;j<n;j++){
        if(T[j].id == R){
          T[j].parent = T[i].id;
          break;
        }
      }
    }
    if(L != -1) {
      for(j=0;j<n;j++){
        if(T[j].id == L){
          T[j].parent = T[i].id;
          break;
        }
      }
    }
  }
  
  int p;
  for(i=0;i<n;i++){
    if(T[i].parent == -1) {
      p = T[i].id;
      break;
    }
  }

  presort(p);
  insort(p);
  postsort(p);

  printf("Preorder\n");
  for(i=0;i<n;i++){
    printf(" %d",P[i]);
    if(i == n-1) printf("\n"); 
  }

  printf("Inorder\n");
  for(i=0;i<n;i++){
    printf(" %d",I[i]);
    if(i == n-1) printf("\n");
  }

  printf("Postorder\n");
  for(i=0;i<n;i++){
    printf(" %d",Po[i]);
    if(i == n-1) printf("\n");
  }
}

void presort(int p){
  int i,x;

  for(i=0;i<n;i++){
    if(T[i].id == p){
      x = i;
      break;
    }
  }

  P[pre] = p;
  pre++;
  
  if(T[x].left != -1) presort(T[x].left);
  if(T[x].right != -1) presort(T[x].right);
}

void insort(int p){
  int i,x;

  for(i=0;i<n;i++){
    if(T[i].id == p){
      x = i;
      break;
    }
  }

  if(T[x].left != -1) insort(T[x].left);

  I[in] = p;
  in++;

  if(T[x].right != -1) insort(T[x].right);
}

void postsort(int p){
  int i,x;

  for(i=0;i<n;i++){
    if(T[i].id == p){
      x = i;
      break;
    }
  }

  if(T[x].left != -1) postsort(T[x].left);
  if(T[x].right != -1) postsort(T[x].right);

  Po[post] = p;
  post++;
}
