#include<stdio.h>
#define NILL -1

typedef struct
{
  int parent;
  int l;
  int r;
  //int id;
}T;

T tree[30];

void PreOrder(int i)
{
  if(i == NILL) return;
  printf(" %d",i);
  //if(i == NILL) return;
  PreOrder(tree[i].l);
  PreOrder(tree[i].r);
}

void InOrder(int i)
{
  if(i == NILL) return;
  InOrder(tree[i].l);
  printf(" %d",i);
  InOrder(tree[i].r);
}

void PostOrder(int i)
{
  if(i == NILL) return;
  PostOrder(tree[i].l);
  PostOrder(tree[i].r);
  printf(" %d",i);
}

int main()
{
  int i;//節点番号
  int n;
  int root = 0;

  scanf("%d",&n);
  
  for(i=0;i < n;i++) tree[i].parent = NILL;

  int v;
  for(i=0;i < n;i++){
    scanf("%d",&v);
    scanf("%d%d",&tree[v].l, &tree[v].r);
    if(tree[v].l != NILL) tree[tree[v].l].parent = v;
    if(tree[v].r != NILL) tree[tree[v].r].parent = v;
  }
  for(i = 0;i < n;i++){
    if(tree[i].parent == NILL) root = i;
  }

  printf("Preorder\n");
  PreOrder(root);
  printf("\n");
  
  printf("Inorder\n");
  InOrder(root);
  printf("\n");

  printf("Postorder\n");
  PostOrder(root);
  printf("\n");
  
  return 0;
}

