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

typedef struct {
  int parent;
  int left;
  int right;
} Binary;

int depth;
Binary T[MAX];

void PreOrder(int);
void InOrder(int);
void PostOrder(int);


int main() {
  int n, i, p, l, r, root;
  
  scanf( "%d" , &n );
  for ( i=0; i<n; i++ ) T[i].parent = T[i].left = T[i].right = NIL;
  for ( i=0; i<n; i++ ) {
    scanf("%d%d%d", &p, &l, &r);
    T[l].parent = T[r].parent = p;
    T[p].left = l;
    T[p].right = r;
  }

  for ( i=0; i<n; i++ ) if ( T[i].parent == NIL ) root = i;
  
  printf( "Preorder\n" );
  PreOrder(root);
  printf( "\nInorder\n" );
  InOrder(root);
  printf( "\nPostorder\n" );
  PostOrder(root);
  printf( "\n" );
  
  return 0;
}


void PreOrder(int u) {
  if ( u == NIL ) return;
  printf( " %d" , u );
  PreOrder(T[u].left);
  PreOrder(T[u].right);
}

void InOrder(int u) {
  if ( u == NIL ) return;
  InOrder(T[u].left);
  printf( " %d" , u );
  InOrder(T[u].right);
}

void PostOrder(int u) {
  if ( u == NIL ) return;
  PostOrder(T[u].left);
  PostOrder(T[u].right);
  printf( " %d" , u );
}

