Create tree of query history