#include<stdio.h>

#define MAX 25
#define NIL -1

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

node T[MAX];
int Pre[MAX],In[MAX],Post[MAX],n;

void Print(int u)
{
  static int c=1;
  
  printf(" %d",u);

  if(c < n)
    {
      c++;
    }
  else
    {
      c = 1;
      printf("\n");
    }
  
  return;
}

void Preorder(int u)
{
  if(u == NIL) return;

  Print(u);
  Preorder(T[u].left);
  Preorder(T[u].right);

  return;
}

void Inorder(int u)
{
  if(u == NIL) return;

  Inorder(T[u].left);
  Print(u);
  Inorder(T[u].right);

  
  return;
}

void Postorder(int u)
{
  if(u == NIL) return;

  Postorder(T[u].left);
  Postorder(T[u].right);
  Print(u);

  return;
}

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

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++) //データの初期化
    {
      T[i].parent = NIL;
      T[i].left = NIL;
      T[i].right = NIL;
    }
  
  for(i = 0 ; i < n ; i++)
    {
      scanf("%d",&id);

      scanf("%d",&left);
      scanf("%d",&right);

      T[left].parent = T[right].parent = id;
      T[id].left = left;
      T[id].right = right;
    }

  for(i = 0 ; i < n ; i++) //root の探索
    {
      if(T[i].parent == NIL) root = i;
    }

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

  
  return 0;
}

