#include<stdio.h>
#include<stdlib.h>

#define N 10000
#define NIL -1

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

node A[N];
int n;

void pre_order(int);
void in_order(int);
void post_order(int);

int main(){
  int left, right, num, root, i;

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    A[i].parent = NIL;
    A[i].left = NIL;
    A[i].right = NIL;
  }

  for(i = 0; i < n; i++){
    scanf("%d%d%d", &num, &left, &right);
    
    A[num].left = left;
    A[num].right = right;

    if(left != NIL)
      A[left].parent = num;
    if(right != NIL)
      A[right].parent = num;
  }
  for(i = 0; i < n; i++)
    if(A[i].parent == NIL)
      root = i;

  printf("Preorder\n");
  pre_order(root);
  printf("\n");
  
  printf("Inorder\n");
  in_order(root);
  printf("\n");

  printf("Postorder\n");
  post_order(root);
  printf("\n");

  return 0;
}

void pre_order(int node){
  if(node == NIL)
    return;

  printf(" %d", node);

  pre_order(A[node].left);
  pre_order(A[node].right);
}

void in_order(int node){
  if(node == NIL)
    return;

  in_order(A[node].left);

  printf(" %d", node);

  in_order(A[node].right);
}

void post_order(int node){
  if(node == NIL)
    return;

  post_order(A[node].left);
  post_order(A[node].right);

  printf(" %d", node);
}
