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

typedef struct{
  int parent;
  int left;
  int right;
}node;
node tree[MAX];


void Preorder(int u){
  if(u == NIL)return;
  printf(" %d",u);
  Preorder(tree[u].left);
  Preorder(tree[u].right);
}

void Inorder(int u){
  if(u == NIL)return;
  Inorder(tree[u].left);
  printf(" %d",u);
  Inorder(tree[u].right);
}

void Postorder(int u){
  if(u == NIL)return;
  Postorder(tree[u].left); 
  Postorder(tree[u].right);
  printf(" %d",u);
}

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

  for(i = 0;i<n;i++)if(tree[i].parent == NIL)root = i;
  printf("Preorder\n");
  Preorder(root);
  printf("\nInorder\n");
  Inorder(root);
  printf("\nPostorder\n");
  Postorder(root);
  printf("\n");
  return 0;
}

