#include<stdio.h>
#define N 25

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

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

node T[N];

int main(){
  int n, i, j;
  int id, left, right;

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

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

  printf("Preorder\n");
  for(i = 0 ; i < n ; i++){
    if(T[i].parent == -1){
      preorder(i);
    }
  }
  printf("\n");

  printf("Inorder\n");
  for(i = 0 ; i < n ; i++){
    if(T[i].parent == -1){
      inorder(i);
    }
  }
  printf("\n");

  printf("Postorder\n");
  for(i = 0 ; i < n ; i++){
    if(T[i].parent == -1){
      postorder(i);
    }
  }
  printf("\n");
    
  return 0;
}

int preorder(int u)
{
  if(u == -1){
     return;
  }
  printf(" %d", u);
  
  preorder(T[u].left);
  preorder(T[u].right);
}

int inorder(int u)
{
  if(u == -1){
    return;
  }
  inorder(T[u].left);
  printf(" %d", u);
  inorder(T[u].right);
}

int postorder(int u)
{
  if(u == -1){
    return;
  }
  postorder(T[u].left);
  postorder(T[u].right);
  printf(" %d", u);
}