#include<stdio.h>
#define M 25
#define NIL -1

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

tree A[M];

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

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

void postorder(int x){
  if(x == NIL) return;
  postorder(A[x].left);
  postorder(A[x].right);
  printf(" %d",x);
}

int main(){
  int i;
  int j;
  int n;
  int count=0;
  int id;
  int height;
  int depth;

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

  for(i=0;i<n;i++){
    scanf("%d %d %d",&id,&height,&depth);
    A[id].left = height;
    A[id].right = depth;
    if(height != NIL) A[height].parent = id;
    if(depth != NIL) A[depth].parent = id;
  }
  
  for(i=0;i<n;i++){
    if(A[i].parent == NIL) break;
  }

  printf("Preorder\n");
  preorder(i);
  printf("\n");

  printf("Inorder\n");
  inorder(i);
  printf("\n");

  printf("Postorder\n");
  postorder(i);
  printf("\n");

  return 0;
}


