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

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

void preorder(Node **, int);
void inorder(Node **, int);
void postorder(Node **, int);

main(){
  int n, i, id, root;
  Node **tree;

  scanf("%d", &n);
  tree = (Node**)malloc(sizeof(Node*)*n);
  for(i=0; i<n; i++){
    tree[i] = (Node*)malloc(sizeof(Node));
    tree[i]->parent = -1;
  }

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

  for(i=0; tree[i]->parent != -1; i++);
  root = i;

  printf("Preorder\n");
  preorder(tree, root);
  printf("\nInorder\n");
  inorder(tree, root);
  printf("\nPostorder\n");
  postorder(tree, root);
  printf("\n");

  return 0;
}

void preorder(Node **nodes, int root){
  if(root == -1) return;

  printf(" %d", root);
  preorder(nodes, nodes[root]->left);
  preorder(nodes, nodes[root]->right);
}

void inorder(Node **nodes, int root){
  if(root == -1) return;

  inorder(nodes, nodes[root]->left);
  printf(" %d", root);
  inorder(nodes, nodes[root]->right);
}

void postorder(Node **nodes, int root){
  if(root == -1) return;

  postorder(nodes, nodes[root]->left);
  postorder(nodes, nodes[root]->right);
  printf(" %d", root);
}