#include <stdio.h>
#define MAX 10000

struct node{
  int p, l, r;
};
struct node T[MAX];
int n;

//???????????????
void pre(int u){
  if(u == -1) return;
  printf(" %d", u);
  pre(T[u].l);
  pre(T[u].r);
}

//???????????????
void ino(int u){
  if(u == -1) return;
  ino(T[u].l);
  printf(" %d", u);
  ino(T[u].r);
}

//???????????????
void pos(int u){
  if(u == -1) return;
  pos(T[u].l);
  pos(T[u].r);
  printf(" %d", u);
}

int main(){
  int i, v, l, r, root;

  scanf("%d", &n);
  for(i = 0; i < n; i++) T[i].p = -1;

  for(i = 0; i < n; i++){
    scanf("%d %d %d", &v, &l, &r);
    T[v].l = l;
    T[v].r = r;
    if(l != -1) T[l].p = v;
    if(r != -1) T[r].p = v;
  }

  for(i = 0; i < n; i++)
    if(T[i].p == -1) root = i;
  printf("Preorder\n");
  pre(root);
  printf("\n");
  printf("Inorder\n");
  ino(root);
  printf("\n");
  printf("Postorder\n");
  pos(root);
  printf("\n");

  return 0;
}