#include <stdio.h>
#define N 25

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

Node Tree[N];

void printPreorder(int x) {
  printf(" %d", x);
  if(Tree[x].left != -1)printPreorder(Tree[x].left);
  if(Tree[x].right != -1)printPreorder(Tree[x].right);
}

void printInorder(int x) {
  if(Tree[x].left != -1)printInorder(Tree[x].left);
  printf(" %d", x);
  if(Tree[x].right != -1)printInorder(Tree[x].right);
}

void printPostorder(int x) {
    if(Tree[x].left != -1)printPostorder(Tree[x].left);
    if(Tree[x].right != -1)printPostorder(Tree[x].right);
    printf(" %d", x);
}

int main() {
  int n, i;
  int id, root;

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

  for (i = 0; i < n; i++) {
    if( Tree[i].parent == -1) {
      root = i;
      break;
    }
  }

  printf("Preorder\n");
  printPreorder(i);
  printf("\n");
  printf("Inorder\n");
  printInorder(i);
  printf("\n");
  printf("Postorder\n");
  printPostorder(i);
  printf("\n");

  return 0;
}