#include <stdio.h>
#include <stdlib.h>
#include <string.h>

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

node tree[25];

void preorder(int id) {
  printf(" %d", id);
  if(tree[id].left != -1) preorder(tree[id].left);
  if(tree[id].right != -1) preorder(tree[id].right);
}

void inorder(int id) {
  if(tree[id].left != -1) inorder(tree[id].left);
  printf(" %d", id);
  if(tree[id].right != -1) inorder(tree[id].right);
}

void postorder(int id) {
  if(tree[id].left != -1) postorder(tree[id].left);
  if(tree[id].right != -1) postorder(tree[id].right);
  printf(" %d", id);
}

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

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

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

  for(i = 0;i < n;i++)
    if(tree[i].parent == -1)
      root = i;

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

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

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

  return 0;
}

