#include<stdio.h>

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

void Preorder( int );
void Inorder( int );
void Postorder( int );

Tree T[25];

int main()
{
  int i, j, n, id, root, left, right;

  scanf("%d", &n);

  for( i=0; i<n; i++ )
    {
      T[i].parent = -1;
    }

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

  for( i=0; i<n; i++ )
    {
      if( T[i].parent == -1 ) root = i;
    }

  printf("Preorder\n");
  Preorder( root );

  printf("\nInorder\n");
  Inorder( root );

  printf("\nPostorder\n");
  Postorder( root );
  printf("\n");

  return 0;
}


void Preorder( int id )
{
  if( id == -1 ) return;

  printf(" %d", id);
  Preorder( T[id].left );
  Preorder( T[id].right );
}


void Inorder( int id )
{
  if( id == -1 ) return;

  Inorder( T[id].left );
  printf(" %d", id);
  Inorder( T[id].right );
}


void Postorder( int id )
{
  if( id == -1 ) return;

  Postorder( T[id].left );
  Postorder( T[id].right );
  printf(" %d", id);
}
  

