#include <stdio.h>
#include <string.h>
#define N 100000

void pre(int);
void in(int);
void pos(int);

typedef struct{
  int parent;
  int left;
  int right;
} data;
data node[N];


int main(){
  int n,i,j,c,t,l,x,d[20],h[20],le,ri,sib[N],f1=0,f2=0,deg[N],root;
  char typ[N][20],a[] = "root",b[] = "leaf",e[] = "internal node";

  scanf("%d",&n);
  for(i = 0;i < n;i++){
    node[i].parent = node[i].left = node[i].right = sib[i] = -1;
  }
  for(i = 0;i < n;i++){
    scanf("%d%d%d",&x,&le,&ri);
    node[x].left = le;
    node[x].right = ri;
    if(le != -1){
      node[le].parent = x;
      f1++;
    }
    if(ri != -1){
      node[ri].parent = x;
      f2++;
    }
    if(le != -1 && ri != -1){
      sib[ri] = le;
      sib[le] = ri;
    }
    deg[x] = f1 + f2;
    f1 = f2 = 0;
  }

  for(i = 0; i < n; i++){
    if(node[i].parent == -1) root = i;
  }

  printf("Preorder\n");
  pre(root);
  printf("\nInorder\n");
  in(root);
  printf("\nPostorder\n");
  pos(root);
  printf("\n");
  
  return 0;
}

void pre(int u){
  if(u == -1) return;
  printf(" %d",u);
  pre(node[u].left);
  pre(node[u].right);
}

void in(int u){
  if(u == -1) return;
  in(node[u].left);
  printf(" %d",u);
  in(node[u].right);
}
void pos(int u){
  if(u == -1) return;
  pos(node[u].left);
  pos(node[u].right);
  printf(" %d",u);
}

