#include<stdio.h>
#define MAX 10000
#define qu -1

struct Node{
  int C,left,right;
};
struct Node D[MAX];
int num;

void Po(int A){
  if(A==qu){
    return;
  }
  printf(" %d",A);
  Po(D[A].left);
  Po(D[A].right);
}

void Io(int A){
  if(A==qu){
    return;
  }
  Io(D[A].left);
  printf(" %d",A);
  Io(D[A].right);
}
void pP(int A){
  if(A == qu){
    return;
  }
  pP(D[A].left);
  pP(D[A].right);
  printf(" %d",A);
}

int main(){
  int i,v,left,right,root;
  scanf("%d",&num);
  for(i=0;i<num;i++){
    D[i].C=qu;
  }

  for(i=0;i<num;i++){
    scanf("%d %d %d",&v,&left,&right);
    D[v].left = left;
    D[v].right= right;
    if(left != qu){
      D[left].C=v;
    }
    if(right != qu){
      D[right].C = v;
    }
  }

    for(i=0;i<num;i++){
      if(D[i].C == qu){
	root = i;
      }
    }
      printf("Preorder\n");
      Po(root);
      printf("\n");
      printf("Inorder\n");
      Io(root);
      printf("\n");
      printf("Postorder\n");
      pP(root);
      printf("\n");
      

      return 0;
}
    

