#include<stdio.h>
#define MAX 100000
#define MIN -1

struct Node{
  int parent, left, right;
};

struct Node T[MAX];

void preOrder(int);
void inOrder(int);
void postOrder(int);

int main(){
  int i,n,x,y,z,root;
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) {
    T[i].parent=MIN;
  }

  for ( i = 0; i < n; i++ ){
    scanf("%d%d%d",&x,&y,&z);
    T[x].left= y;
    T[x].right= z;
    if ( y!=MIN) T[y].parent=x;
    if ( z!=MIN) T[z].parent=x;
  }

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

void preOrder(int u){
  if (u==MIN) return;
  printf(" %d", u);
  preOrder(T[u].left);
  preOrder(T[u].right);
}
void inOrder(int u){
  if (u==MIN) return;
  inOrder(T[u].left);
  printf(" %d", u);
  inOrder(T[u].right);
}
void postOrder(int u){
  if (u==MIN) return;
  postOrder(T[u].left);
  postOrder(T[u].right);
  printf(" %d", u);
}

