class Node(): def __init__(self,data=None): self.data=data self.left=None self.right=None def insert(self,data): if self.data: if data<self.data: if self.left: self.left.insert(data) else: self.left=Node(data) else: if self.right: self.right.insert(data) else: self.right=Node(data) else: self.data=data def preorder(self): print(self.data,end=' ') if self.left: self.left.preorder() if self.right: self.right.preorder() while 1: try: a=input() b=list(map(int,input().split())) c=Node() for d in b: c.insert(d) c.preorder() print() except: break