#include <stdio.h>

#define MAX 25
#define NIL -1

typedef struct{
  int parent,left,right;
}TREE;

void PreParse(TREE [],int);
void InParse(TREE [],int);
void PostParse(TREE [],int);

int main(){
  TREE tree[MAX];
  int i;
  int id,left,right,n;
  int root;

  for (i = 0;i < MAX;i++){
    tree[i].parent = NIL;
    tree[i].left = NIL;
    tree[i].right = NIL;
  }

  scanf("%d",&n);

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

    if (left != NIL)
    tree[left].parent = id;

    if (right != NIL)
    tree[right].parent = id;

  }

  for (i = 0;i < n;i++)
    if (tree[i].parent == NIL)
      root = i;
  
  printf("Preorder\n");
  PreParse(tree,root);
  printf("\nInorder\n");
  InParse(tree,root);
  printf("\nPostorder\n");
  PostParse(tree,root);
  printf("\n");
  
  return 0;
}

void PreParse(TREE tree[],int u){
  if (u == NIL)
    return;

  printf(" %d",u);
  PreParse(tree,tree[u].left);
  PreParse(tree,tree[u].right);
}

void InParse(TREE tree[],int u){
  if (u == NIL)
    return;

  InParse(tree,tree[u].left);
  printf(" %d",u);
  InParse(tree,tree[u].right);
}

void PostParse(TREE tree[],int u){
  if (u == NIL)
    return;

  PostParse(tree,tree[u].left);
  PostParse(tree,tree[u].right);
  printf(" %d",u);
}

