#include <stdio.h>
#define NIL -1
#define Max 25

typedef struct { int p, l, r; } Node;
Node T[Max];
int n, i;

void preOrder(int u) {
  if ( u == NIL )
    return;
  printf(" %d", u);
  preOrder(T[u].l);
  preOrder(T[u].r);
}

void inOrder(int u) {
  if ( u == NIL )
    return;
  inOrder(T[u].l);
  printf(" %d", u);
  inOrder(T[u].r);
}

void postOrder(int u) {
  if ( u == NIL )
    return;
  postOrder(T[u].l);
  postOrder(T[u].r);
  printf(" %d", u);
}

int main(void) {
  int v, left, right, root;
  scanf("%d", &n);
  for ( i = 0; i < n; ++i ) T[i].p = NIL;
  for ( i = 0; i < n; ++i ) {
    scanf("%d %d %d", &v, &left, &right);
    T[v].l = left;
    T[v].r = right;
    if ( left != NIL ) { T[left].p = v; }
    if ( right != NIL ) { T[right].p = v; }
  }
  for ( i = 0; i < n; ++i )
    if ( T[i].p == NIL)
      root = i;
  puts("Preorder");
  preOrder(root); putchar('\n');
  puts("Inorder");
  inOrder(root); putchar('\n');
  puts("Postorder");
  postOrder(root); putchar('\n');
}
