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

#define WHITE 1
#define BLACK 0

/*typedef struct node{
  int num;
  struct node *left;
  struct node *right;
} Node;

Node *nil;
*/int n;
int color[25];
/*
Node *makeTree(int i,int x[],int l[],int r[]){
  Node *newNode;
  newNode = (Node *)malloc(sizeof(Node));

  color[i] = BLACK;

  int j=0;

  newNode->num = x[i];
  if(l[i]==-1) newNode->left = NULL;
  else{
    while(1){
      if(x[j]==l[i]) break;
      j++;
    }
    newNode->left = makeTree(j,x,l,r);
  }
  if(r[i]==-1) newNode->right = NULL;
  else{
    j=0;
    while(1){
      if(x[j]==r[i]) break;
      j++;
    }
    newNode->right = makeTree(r[i],x,l,r);
  }

  return newNode;
}*/

void xTox2(int x[],int x2[]){
  int i;
  for(i=0;i<n;i++){
    x2[x[i]] = i;
  }
}

void preorder(int j,int x[],int l[],int r[],int x2[]){
  printf(" %d",x[j]);
  if(l[j] != -1) preorder(x2[l[j]],x,l,r,x2);
  if(r[j] != -1) preorder(x2[r[j]],x,l,r,x2);
}

void inorder(int j,int x[],int l[],int r[],int x2[]){
  if(l[j] != -1) inorder(x2[l[j]],x,l,r,x2);
  printf(" %d",x[j]);
  if(r[j] != -1) inorder(x2[r[j]],x,l,r,x2);
}

void postorder(int j,int x[],int l[],int r[],int x2[]){
  if(l[j] != -1) postorder(x2[l[j]],x,l,r,x2);
  if(r[j] != -1) postorder(x2[r[j]],x,l,r,x2);
  printf(" %d",x[j]);
}

int main(){
  int i,j;
  int x[25],l[25],r[25];
  int x2[25];

  scanf("%d",&n);

  for(i=0;i<n;i++) color[i] = WHITE;

  for(i=0;i<n;i++){
    scanf("%d%d%d",&x[i],&l[i],&r[i]);

    if(l[i]!=-1) color[l[i]] = BLACK;
    if(r[i]!=-1) color[r[i]] = BLACK;
  }

  xTox2(x,x2);

  for(i=0;i<n;i++){
    if(color[i]==WHITE) j=i;
    //printf("%d %d\n",i,color[i]);
    color[i]=WHITE;
  }
  //printf("%d\n",j);

  for(i=0;i<n;i++){
    if(x[i]==j){
       j=i;
       break;
     }
    //printf("%d %d\n",i,x[i]);
  }


  //printf("%d\n",j);

  // nil = (Node *)malloc(sizeof(Node));
  // nil = makeTree(j,x,l,r);

  // for(i=0;i<n;i++){
  //   printf("%d %d\n",i,color[i]);
  // }


  printf("Preorder\n");
  preorder(j,x,l,r,x2);
  printf("\nInorder\n");
  inorder(j,x,l,r,x2);
  printf("\nPostorder\n");
  postorder(j,x,l,r,x2);
  printf("\n");

  return 0;
}

