import sys

def main():
    n = input()
    tree = MyTree(n)
    for i in range(n):
        id_cn = map(int,raw_input().split())
        id_node = id_cn.pop(0)
        
        tree.add(id_node,None,id_cn)
    
    tree.search_children()
    tree.set_depth_height(tree.nodes[tree.id_root],0)

    print "Preorder"
    tree.preorder(tree.nodes[tree.id_root])
    print ""
    print "Inorder"
    tree.inorder(tree.nodes[tree.id_root])
    print ""
    print "Postorder"
    tree.postorder(tree.nodes[tree.id_root])
    print""

    
class MyTree():
    def __init__(self,num_nodes):
        self.nodes = [MyNode() for i in range(num_nodes)]
        self.id_root = None

    def add(self,id_node,id_parent,id_children):
        node = self.nodes[id_node]
        node.id_self = id_node
        node.id_parent = id_parent
        node.id_children = id_children
    
    def search_children(self):
        for node in self.nodes:
            if all(item==-1 for item in node.id_children):
                node.node_type = "leaf"
                node.degree = 0
            else:
                node.node_type = "internal node"
                l = node.id_children[0]
                r = node.id_children[1]
                if l == -1:
                    node.degree = 1
                    self.nodes[r].id_parent = node.id_self
                    self.nodes[r].sibling = l
                elif r == -1:
                    node.degree = 1
                    self.nodes[l].id_parent = node.id_self
                    self.nodes[l].sibling = r
                else:
                    node.degree = 2
                    self.nodes[l].id_parent = node.id_self
                    self.nodes[r].id_parent = node.id_self
                    self.nodes[l].sibling = r
                    self.nodes[r].sibling = l

        for node in self.nodes:
            if node.id_parent == None:
                node.id_parent = -1
                node.node_type = "root"
                self.id_root = node.id_self
                break

    def set_depth_height(self,node,depth):
        node.depth = depth
        l_height = []
        if all(item==-1 for item in node.id_children):
            node.height = 0
            return 0
        else:
            for item in node.id_children:
                if not item == -1:
                    l_height.append(self.set_depth_height(self.nodes[item],depth+1))
            height = max(l_height)+1
            node.height = height
            return height

    def preorder(self,node):
        sys.stdout.write(" {}".format(node.id_self))
        l,r = node.id_children
        if not l == -1:
            self.preorder(self.nodes[l])
        if not r == -1:
            self.preorder(self.nodes[r])    

    def inorder(self,node):
        l,r = node.id_children
        if not l == -1:
            self.inorder(self.nodes[l])
        sys.stdout.write(" {}".format(node.id_self))
        if not r == -1:
            self.inorder(self.nodes[r])

    def postorder(self,node):
        l,r = node.id_children
        if not l == -1:
            self.postorder(self.nodes[l])
        if not r == -1:
            self.postorder(self.nodes[r])
        sys.stdout.write(" {}".format(node.id_self))
                


class MyNode():
    def __init__(self):
        self.id_self = None
        self.id_parent = None
        self.id_children = None
        self.depth = None
        self.node_type = None
        self.n_children = 0
        self.sibling = -1
        self.degree = 0
        self.height = 0


if __name__ == "__main__":
    main()

Measured memory_bytes: 6596