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

typedef struct list tree;

struct list{
  int n;
  tree *l, *r;
};

int add_t(int n, int l, int r, tree *t){
  tree *lt, *rt;
  if(t->n == -1) return 0;
  else if(t->n == n){

    lt = malloc(sizeof(tree));
    t->l = lt;
    lt->n = l;
    lt->l = NULL;
    lt->r = NULL;

    rt = malloc(sizeof(tree));
    t->r = rt;
    rt->n = r;
    rt->l = NULL;
    rt->r = NULL;
  }else if(t->l != NULL && add_t(n, l, r, t->l)) return 1;
  else if(t->r != NULL && add_t(n, l, r, t->r)) return 1;

  return 0;
}

void output(tree *t, int mode){
  if(t->n != -1){
    if(mode == -1) printf(" %d", t->n);
    output(t->l, mode);
    if(mode == 0) printf(" %d", t->n);
    output(t->r, mode);
    if(mode == 1) printf(" %d", t->n);
  }
}

int main(){
  int i, num, n, l, r;
  tree top;

  top.l = NULL;
  top.r = NULL;

  scanf("%d", &num);

  for(i = 0; i < num; i++){
    scanf("%d %d %d", &n, &l, &r);
    if(i == 0) top.n = n;
    add_t(n, l, r, &top);
  }

  printf("Preorder\n");
  output(&top, -1);
  printf("Inorder\n");
  output(&top, 0);
  printf("Postorder\n");
  output(&top, 1);
  printf("\n");

  return 0;
}

