import std.stdio;
import std.conv;
import std.algorithm;
import std.range;
import std.string;
import std.typecons;
import std.math;
import std.random;
import std.range;
import std.functional;
import std.container;
class t
{
    int parent, left, right;
    this()
    {
        parent = left = right = -1;
    }

    int depth;
    int height;
}
void dep(t[] tt, int i, int d = 0)
{
    if (i == -1)
    {
        return;
    }
    tt[i].depth = d;
    dep(tt, tt[i].left, d + 1);
    dep(tt, tt[i].right, d + 1);
}
int hei(t[] tt, int i)
{
    auto a1 = 0, a2 = 0;
    if (tt[i].left != -1)
        a1 = hei(tt, tt[i].left) + 1;
    if (tt[i].right != -1)
        a2 = hei(tt, tt[i].right) + 1;
    tt[i].height = max(a1, a2);
    return tt[i].height;
}
void pre(t[] tt, int i)
{
    if (i == -1)
    {
        return;
    }
    write(" ", i);
    pre(tt, tt[i].left);
    pre(tt, tt[i].right);
}
void in_(t[] tt, int i)
{
    if (i == -1)
    {
        return;
    }
    in_(tt, tt[i].left);
    write(" ", i);
    in_(tt, tt[i].right);
}
void post(t[] tt, int i)
{
    if (i == -1)
    {
        return;
    }
    post(tt, tt[i].left);
    post(tt, tt[i].right);
    write(" ", i);
}
void main()
{
    auto c = readln.strip.to!int;
    auto tt = new t[c];
    foreach (i; 0..c)
        tt[i] = new t();
    foreach (i; 0..c)
    {
        auto a = readln().strip.split(" ").map!(to!int).array;
        if (a[1] != -1)
        {
            tt[a[0]].left = a[1];
            tt[a[1]].parent = a[0];
        }
        if (a[2] != -1)
        {
            tt[a[0]].right = a[2];
            tt[a[2]].parent = a[0];
        }
    }
    foreach (i; 0..c)
    {
        if (tt[i].parent == -1)
        {
            writeln("Preorder");
            pre(tt, i);
            writeln();
            writeln("Inorder");
            in_(tt, i);
            writeln();
            writeln("Postorder");
            post(tt, i);
            writeln();
        }
    }
}

