#include<iostream>

struct binary_tree{
  int parent,sibling,degree,depth,height;
  std::string type;
  int left,right;
  static int decide_type(binary_tree [],int);
  static void give(binary_tree [],int);
  static void enter_from_root(binary_tree [],int);
  static int return_maxdep(binary_tree [],int,int);
  static void preorder(binary_tree [],int);
  static void inorder(binary_tree [],int);
  static void postorder(binary_tree [],int);
};

int binary_tree::decide_type(binary_tree T[],int n){
  int root=-2;
  for(int i=0;i<n;i++){
    if(T[i].parent==-1){
      T[i].type="root";
      root=i;
    }else if(T[i].degree==0){
      T[i].type="leaf";
    }else{
      T[i].type="internal node";
    }
  }
  return root;
}

void binary_tree::give(binary_tree T[],int i){
  int left=T[i].left;
  int right=T[i].right;
  if(T[i].degree==2){
    T[left].depth=T[i].depth+1;
    T[right].depth=T[i].depth+1;
    give(T,left);
    give(T,right);
  }else if(T[i].degree==0){
    //do nothing
  }else if(left==-1){
    T[right].depth=T[i].depth+1;
    give(T,right);
  }else{
    T[left].depth=T[i].depth+1;
    give(T,left);
  }
}

void binary_tree::preorder(binary_tree T[],int root){
  std::cout<<" "<<root;
  int left=T[root].left;
  int right=T[root].right;
  if(left==-1&&right==-1){
  }else if(right==-1){
    preorder(T,left);
  }else if(left==-1){
    preorder(T,right);
  }else{
    preorder(T,left);
    preorder(T,right);
  }
}

void binary_tree::inorder(binary_tree T[],int root){
  int left=T[root].left;
  int right=T[root].right;
  if(left==-1&&right==-1){
    std::cout<<" "<<root;
    }else if(right==-1){
    inorder(T,left);
    std::cout<<" "<<root;
  }else if(left==-1){
    std::cout<<" "<<root;
    inorder(T,right);
  }else{
    inorder(T,left);
    std::cout<<" "<<root;
    inorder(T,right);
  }
}

void binary_tree::postorder(binary_tree T[],int root){
  int left=T[root].left;
  int right=T[root].right;
  if(left==-1&&right==-1){
    std::cout<<" "<<root;
    }else if(right==-1){
    postorder(T,left);
    std::cout<<" "<<root;
  }else if(left==-1){
    postorder(T,right);
    std::cout<<" "<<root;
  }else{
    postorder(T,left);
    postorder(T,right);
    std::cout<<" "<<root;

  }
}

int binary_tree::return_maxdep(binary_tree T[],int i,int max_depth){
  if(T[i].depth>max_depth)max_depth=T[i].depth;
  int left=T[i].left;
  int right=T[i].right;
  if(T[i].degree==2){
    int maxl=return_maxdep(T,left,max_depth);
    int maxr=return_maxdep(T,right,max_depth);
    if(maxl>max_depth)max_depth=maxl;
    if(maxr>max_depth)max_depth=maxr;
  }else if(T[i].degree==0){
    //do nothing
  }else if(left==-1){
    int max=return_maxdep(T,right,max_depth);
    if(max>max_depth)max_depth=max;
  }else{
    int max=return_maxdep(T,left,max_depth);
    if(max>max_depth)max_depth=max;
  }
  return max_depth;
}

int main(){
  int n;
  std::cin>>n;
  binary_tree T[n];
  for(int i=0;i<n;i++){
    T[i].parent=-1;
    T[i].sibling=-1;
  }
  //初期化 以下入力
  for(int i=0;i<n;i++){
    int x,left,right;
    std::cin>>x>>left>>right;
      T[x].left=left;
      T[x].right=right;
      if(left==-1&&right==-1){
        T[x].degree=0;
      }else if(left==-1){
        T[x].degree=1;
        T[right].parent=x;
      }else if(right==-1){
        T[x].degree=1;
        T[left].parent=x;
      }else{
        T[x].degree=2;
        T[left].parent=x;
        T[right].parent=x;
        T[left].sibling=right;
        T[right].sibling=left;
      }
  }
  int root=binary_tree::decide_type(T,n);
  T[root].depth=0;
  binary_tree::give(T,root);
  for(int i=0;i<n;i++){
    int max_depth=0;
    int height=binary_tree::return_maxdep(T,i,max_depth)-T[i].depth;
    T[i].height=height;
  }
  std::cout<<"Preorder"<<std::endl;
  binary_tree::preorder(T,root);
  std::cout<<std::endl;
  std::cout<<"Inorder"<<std::endl;
  binary_tree::inorder(T,root);
  std::cout<<std::endl;
  std::cout<<"Postorder"<<std::endl;
  binary_tree::postorder(T,root);
  std::cout<<std::endl;
}



Measured memory_bytes: 3224