class _Node {
  constructor(id, parentId, leftId, rightId) {
    this.id = id;
    this.parentId = parentId;
    this.leftId = leftId;
    this.rightId = rightId;
  }
}

class BinaryTree {
  constructor() {
    this.nodes = [];
  }

  static get Node() {return _Node;}

  get root() { return this.nodes.find(n => n.parentId === -1); }

  add(id, leftId, rightId) { this.nodes[id] = new BinaryTree.Node(id, -1, leftId, rightId); }

  find(id) { return this.nodes[id]; }

  connect() {
    this.nodes.forEach(n => {
      if (n.leftId !== -1) this.nodes[n.leftId].parentId = n.id;
      if (n.rightId !== -1) this.nodes[n.rightId].parentId = n.id;
    });
  }

  preorder(id = this.root.id) {
    if (id === -1) return;
    let n = this.find(id);
    process.stdout.write(` ${id}`);
    this.preorder(n.leftId);
    this.preorder(n.rightId);
  }

  inorder(id = this.root.id) {
    if (id === -1) return;
    let n = this.find(id);
    this.inorder(n.leftId);
    process.stdout.write(` ${id}`);
    this.inorder(n.rightId);
  }

  postorder(id = this.root.id) {
    if (id === -1) return;
    let n = this.find(id);
    this.postorder(n.leftId);
    this.postorder(n.rightId);
    process.stdout.write(` ${id}`);
  }
}

(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  let tree = new BinaryTree();
  lines.map(l => l.split(' ').map(Number)).forEach(line => tree.add(...line));
  tree.connect();
  console.log('Preorder');
  tree.preorder();
  console.log('\nInorder');
  tree.inorder();
  console.log('\nPostorder');
  tree.postorder();
})();

