building and printing a tree