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

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

Node A[25];

void inorder(int u){
  if(A[u].left != NIL) inorder(A[u].left);
  printf(" %d",u);
  if(A[u].right != NIL) inorder(A[u].right);
}

void preorder(int u){
  printf(" %d",u);
  if(A[u].left != NIL) preorder(A[u].left);
  if(A[u].right != NIL) preorder(A[u].right);
}

void postorder(int u){
  if(A[u].left != NIL) postorder(A[u].left);
  if(A[u].right != NIL) postorder(A[u].right);
  printf(" %d",u);
}

int main(){
  int n,i,id,root,l,r;

  scanf("%d",&n);
  for(i = 0; i < n; i++) A[i].parent = NIL;
  for(i = 0; i < n; i++){
    scanf("%d %d %d",&id,&l,&r);
    A[id].left = l;
    A[id].right = r;
    if(A[id].left != NIL) A[A[id].left].parent = id;
    if(A[id].right != NIL) A[A[id].right].parent = id;
  }
 

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

