with open("test.txt", "r") as f:
    class BinarySearchTree:
        def __init__(self):
            self.root = None

        def insert(self, x):
            node = self.Node(x)
            if self.root is None:
                self.root = node
            else:
                here = self.root
                #
                temp = None
                while here is not None:
                    temp = here
                    if x < here.node:
                        here = here.left
                    elif x > here.node:
                        here = here.right
                if x < temp.node:
                    temp.left = node
                elif x > temp.node:
                    temp.right = node

        def inorder(self, answer, address = "root"):
            if address is "root":
                address = self.root
            elif address is None:
                return
            self.inorder(answer, address.left)
            answer.append(address.node)
            self.inorder(answer, address.right)

        def preorder(self, answer, address = "root"):
            if address is "root":
                address = self.root
            elif address is None:
                return
            answer.append(address.node)
            self.preorder(answer, address.left)
            self.preorder(answer, address.right)

        class Node:
            def __init__(self, x):
                self.node = x
                self.left = None
                self.right = None

    query = int(f.readline())
    bt = BinarySearchTree()
    for _ in range(query):
        command = f.readline()
        if command[0] == "i":
            bt.insert(int(command.split(" ")[1]))
        else:
            a = []
            bt.inorder(a)
            print(*a)
            a = []
            bt.preorder(a)
            print(*a)

### FIXED CODE ###

class BinarySearchTree:
    def __init__(self):
        self.root = None

    def insert(self, x):
        node = self.Node(x)
        if self.root is None:
            self.root = node
        else:
            here = self.root
            #
            temp = None
            while here is not None:
                temp = here
                if x < here.node:
                    here = here.left
                elif x > here.node:
                    here = here.right
            if x < temp.node:
                temp.left = node
            elif x > temp.node:
                temp.right = node

    def inorder(self, answer, address = "root"):
        if address is "root":
            address = self.root
        elif address is None:
            return
        self.inorder(answer, address.left)
        answer.append(address.node)
        self.inorder(answer, address.right)

    def preorder(self, answer, address = "root"):
        if address is "root":
            address = self.root
        elif address is None:
            return
        answer.append(address.node)
        self.preorder(answer, address.left)
        self.preorder(answer, address.right)

    class Node:
        def __init__(self, x):
            self.node = x
            self.left = None
            self.right = None

query = int(input())
bt = BinarySearchTree()
for _ in range(query):
    command = input()
    if command[0] == "i":
        bt.insert(int(command.split(" ")[1]))
    else:
        a = []
        bt.inorder(a)
        print(" ", end = "")
        print(*a)
        a = []
        bt.preorder(a)
        print(" ", end = "")
        print(*a)