#include <stdio.h>

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

void setup(struct Node node[], int n) {
  for (int i = 0; i < n; i++) {
    node[i].parent = -1;
    node[i].left = -1;
    node[i].right = -1;
  }
}

void input(struct Node node[], int n) {
  int id, cleft , cright;
  for (int i = 0; i < n; i++) {
    scanf("%d", &id);
    scanf("%d", &cleft);
    scanf("%d", &cright);
    
    node[id].left = cleft;
    node[id].right = cright;
    node[cleft].parent = id;
    node[cright].parent = id;
  }
}

int root_search(struct Node node[], int n) {
  for (int i = 0; i < n; i++) {
    if (node[i].parent == -1)
      return i;
  }
}

void preorder_tree_walk(struct Node node[], int id) {
  printf(" %d", id);
  if (node[id].left != -1)
    preorder_tree_walk(node, node[id].left);
  if (node[id].right != -1)
    preorder_tree_walk(node, node[id].right);
}

void inorder_tree_walk(struct Node node[], int id) {
  if (node[id].left == -1 && node[id].right == -1)
    printf(" %d", id);
  else {
    if (node[id].left != -1)
      inorder_tree_walk(node, node[id].left);
    printf(" %d", id);
    if (node[id].right != -1)
      inorder_tree_walk(node, node[id].right);
  }
}

void postorder_tree_walk(struct Node node[], int id) {
  if (node[id].left != -1)
    postorder_tree_walk(node, node[id].left);
  if (node[id].right != -1)
    postorder_tree_walk(node, node[id].right);
  printf(" %d", id);
}

int main(void) {
  int n, root;
  struct Node node[25]; 

  scanf("%d", &n);

  setup(node, n);
  input(node, n);

  root = root_search(node, n);

  printf("Preorder\n");
  preorder_tree_walk(node, root);

  printf("\nInorder\n");
  inorder_tree_walk(node, root);

  printf("\nPostorder\n");
  postorder_tree_walk(node, root);
  printf("\n");

  return 0;
}

