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

typedef struct list tree;

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

void add_t(tree *t, int n, int l, int r){
    t[n].n = n;
    t[n].ln = l;
    t[n].rn = r;
    t[n].l = NULL;
    t[n].r = NULL;
}

void str_t(int i, tree *t){
  if(t[i].ln != -1){
    t[i].l = &t[t[i].ln];
    str_t(t[i].ln, t);
  }
  if(t[i].rn != -1){
    t[i].r = &t[t[i].rn];
    str_t(t[i].rn, t);
  }
}

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

int main(){
  int i, num, n, l, r, *f;
  tree *t;

  scanf("%d", &num);

  t = malloc(num * sizeof(tree));
  f = malloc(num * sizeof(int));

  for(i = 0; i < num; i++) f[i] = 1;

  for(i = 0; i < num; i++){
    scanf("%d %d %d", &n, &l, &r);
    add_t(t, n, l, r);
    f[l] = 0;
    f[r] = 0;
  }

  for(i = 0; i < num; i++){
    if(f[i]){
       str_t(i, t);
       break;
     }
  }

  printf("Preorder\n");
  output(&t[i], -1);
  printf("\nInorder\n");
  output(&t[i], 0);
  printf("\nPostorder\n");
  output(&t[i], 1);
  printf("\n");

  return 0;
}
