class SimpleBinaryTree:
    class Node:
        def __init__(self):
            self.num = -1
            self.parent = -1
            self.right = -1
            self.left = -1
    
    def __init__(self, n):
        self.node_num = n
        self.nodes = []
        for i in range(n):
            node = self.Node()
            self.nodes.append(node)
    
    def load(self, tree_info):
        for i in range(self.node_num):
            self.nodes[i].num = tree_info[i][0]
            self.nodes[i].left = tree_info[i][1]
            self.nodes[i].right = tree_info[i][2]
            if self.nodes[i].left != -1:
                self.nodes[self.nodes[i].left].parent = self.nodes[i].num
            if self.nodes[i].right != -1:
                self.nodes[self.nodes[i].right].parent = self.nodes[i].num

    
    def print_preorder(self, i):
        if self.nodes[i].left == -1 and self.nodes[i].right == -1:
            return [self.nodes[i].num]
        elif self.nodes[i].left == -1:
            return [self.nodes[i].num] + self.print_preorder(self.nodes[i].right)
        elif self.nodes[i].right == -1:
            return [self.nodes[i].num] + self.print_preorder(self.nodes[i].left)
        else:
            return [self.nodes[i].num] + self.print_preorder(self.nodes[i].left) + self.print_preorder(self.nodes[i].right)


    def print_inorder(self, i):
        if self.nodes[i].left == -1 and self.nodes[i].right == -1:
            return [self.nodes[i].num]
        elif self.nodes[i].left == -1:
            return [self.nodes[i].num] + self.print_inorder(self.nodes[i].right)
        elif self.nodes[i].right == -1:
#            return [self.nodes[i].num] + self.print_inorder(self.nodes[i].left)
            return  self.print_inorder(self.nodes[i].left) + [self.nodes[i].num]
        else:
            return self.print_inorder(self.nodes[i].left) + [self.nodes[i].num] + self.print_inorder(self.nodes[i].right)


    def print_postorder(self, i):
        if self.nodes[i].left == -1 and self.nodes[i].right == -1:
            return [self.nodes[i].num]
        elif self.nodes[i].left == -1:
#            return [self.nodes[i].num] + self.print_postorder(self.nodes[i].right)
            return self.print_postorder(self.nodes[i].right) + [self.nodes[i].num] 
        elif self.nodes[i].right == -1:
#            return [self.nodes[i].num] + self.print_postorder(self.nodes[i].left)
            return self.print_postorder(self.nodes[i].left) + [self.nodes[i].num]
        else:
            return self.print_postorder(self.nodes[i].left) + self.print_postorder(self.nodes[i].right) + [self.nodes[i].num]


if __name__ == '__main__':
    n = int(input())
    tree_info = [[None]] * n
    for i in range(n):
        line = list(map(int, input().rstrip().split()))
        tree_info[line[0]] = line
    sbt = SimpleBinaryTree(n)
    sbt.load(tree_info)
    for node in sbt.nodes:
        if node.parent == -1:
            top = node.num
            break
    print('Preorder')
    print(' ' + ' '.join(map(str,sbt.print_preorder(top))).rstrip())
    print('Inorder')
    print(' ' + ' '.join(map(str,sbt.print_inorder(top))).rstrip())
    print('Postorder')
    print(' ' + ' '.join(map(str,sbt.print_postorder(top))).rstrip())



Measured memory_bytes: 5628