#include<stdio.h>

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

Node T[25];

void preorder(int i){
  if(i == -1) return;
  printf(" %d",i);
  preorder(T[i].left);
  preorder(T[i].right);
}

void inorder(int i){
  if(i == -1) return;
  inorder(T[i].left);
  printf(" %d",i);
  inorder(T[i].right);
}

void postorder(int i){
  if(i == -1) return;
  postorder(T[i].left);
  postorder(T[i].right);
  printf(" %d",i);
}

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

  scanf("%d",&n);

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

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

  for(i = 0;i < n;i++){
    if(T[i].parent == -1) 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;
}

