#include <stdio.h>
#define MAX 25
#define NIL -1
 
typedef struct node {
  int parent;
  int left;
  int right;
}Node;
 
 
Node U[MAX];
int n;

void preorder(int u) {

  if( u == NIL ) return;
 
  printf(" %d", u);
  preorder(U[u].left);
  preorder(U[u].right);
}
 
void inorder(int u){

  if( u == NIL )return;
 
  inorder(U[u].left);

  printf(" %d", u);

  inorder(U[u].right);
}
 
void postorder(int u) {

  if(u == NIL)return;
 
  postorder(U[u].left);

  postorder(U[u].right);

  printf(" %d", u);
}


 
int main() {

  int id, data, r,i, j;
 
  scanf("%d", &n);
 
  for (i = 0;i < n;i ++ )
    {
    U[i].parent = NIL;
    U[i].left = NIL;
    U[i].right = NIL;
  }
 
  for (i = 0;i < n;i ++ )
    {
    scanf("%d", &id);

    for (j = 0;j < 2;j ++)
      {
      scanf("%d", &data);

      if(j == 0)U[id].left = data;

      else U[id].right = data;

      U[data].parent = id;
    }
  }
 
    for (i = 0;i < n;i ++ )

      if ( U[i].parent == NIL )

	r = i;
 
    printf("Preorder\n");

    preorder(r);

    printf("\n");

    printf("Inorder\n");

    inorder(r);

    printf("\n");

    printf("Postorder\n");

    postorder(r);

    printf("\n");
 
  return 0;
}
 